﻿Class MainWindow

    Private wrk As ComponentModel.BackgroundWorker

    Private Function ContainsData(ByVal dat As Byte(), ByVal Start As Integer, ByVal LengthToCheck As Integer, ByVal ParamArray ToFind() As Byte) As Boolean

        Dim res As Boolean
        Dim i As Integer
        Dim m As Integer
        Dim j As Integer
        Dim n As Integer

        res = False
        n = ToFind.Length
        m = LengthToCheck - m
        i = 0
        While i < m
            j = 0
            While j < n
                If dat(Start + i + j) <> ToFind(j) Then
                    Exit While
                Else
                    j = j + 1
                End If
            End While
            If j = n Then
                res = True
                Exit While
            Else
                i = i + 1
            End If
        End While
        Return res

    End Function

    Private Function WordsInLinePack(ByVal LinePack As List(Of String)) As List(Of WordData)

        Dim WordsList As List(Of WordData)
        Dim WordToWrite As WordData
        Dim lin As String
        Dim c As Char
        Dim Stage As Integer
        Dim CharUsed As Boolean
        Dim i As Integer
        Dim j As Integer
        Dim WordCount As Integer

        WordsList = New List(Of WordData)
        Stage = 0
        i = 0
        WordCount = 0
        WordToWrite = Nothing
        For Each lin In LinePack
            j = 0
            For Each c In lin
                CharUsed = False
                Do
                    Select Case Stage
                        Case 0
                            If Char.IsWhiteSpace(c) Then
                                CharUsed = True
                            Else
                                WordToWrite = New WordData
                                WordToWrite.Index = WordCount
                                WordToWrite.Line = i
                                WordToWrite.Start = j
                                WordCount = WordCount + 1
                                Stage = 1
                            End If
                        Case 1
                            If Char.IsWhiteSpace(c) Then
                                Stage = 2
                            Else
                                WordToWrite.Word = WordToWrite.Word & Char.ToUpper(c)
                                CharUsed = True
                            End If
                        Case 2
                            If Char.IsWhiteSpace(c) Then
                                CharUsed = True
                            Else
                                WordToWrite.NextWordStartLine = i
                                WordToWrite.NextWordStart = j
                                WordsList.Add(WordToWrite)
                                WordToWrite = New WordData
                                WordToWrite.Index = WordCount
                                WordToWrite.Line = i
                                WordToWrite.Start = j
                                WordCount = WordCount + 1
                                Stage = 1
                            End If
                    End Select
                Loop While Not CharUsed
                j = j + 1
            Next
            i = i + 1
        Next
        If WordToWrite IsNot Nothing AndAlso WordToWrite.Word.Length > 0 Then
            WordToWrite.NextWordStartLine = i
            WordToWrite.NextWordStart = j
            WordsList.Add(WordToWrite)
        End If
        Return WordsList

    End Function

    Private Function StartingWord(ByVal WordsList As List(Of WordData), ByVal ParamArray WordsToSearch As String()) As WordData

        Dim WordToReturn As WordData
        Dim i As Integer
        Dim Found As Boolean
        Dim j As Integer
        Dim k As Integer

        WordToReturn = Nothing
        i = 0
        If i < WordsList.Count Then
            Do
                Found = False
                j = i
                k = 0
                While k < WordsToSearch.Count AndAlso j < WordsList.Count
                    If Not WordsList(j).Word.Equals(WordsToSearch(k)) Then
                        Exit While
                    Else
                        k = k + 1
                        j = j + 1
                    End If
                End While
                If k >= WordsToSearch.Count Then
                    Found = True
                    WordToReturn = WordsList(i)
                Else
                    i = i + 1
                End If
            Loop While Not Found AndAlso i < WordsList.Count
        End If
        Return WordToReturn

    End Function

    Public Function EraseWord(ByVal WordToErase As WordData, ByVal LinePack As List(Of String)) As List(Of WordData)

        Dim lin As String
        Dim i As Integer

        i = WordToErase.NextWordStartLine - WordToErase.Line
        If i = 0 Then
            lin = LinePack(WordToErase.Line)
            lin = lin.Remove(WordToErase.Start, WordToErase.NextWordStart - WordToErase.Start)
            LinePack(WordToErase.Line) = lin
        Else
            lin = LinePack(WordToErase.Line)
            lin = lin.Substring(0, WordToErase.Start)
            LinePack(WordToErase.Line) = lin
            If WordToErase.NextWordStart < LinePack.Count Then
                lin = LinePack(WordToErase.NextWordStart)
                lin = lin.Substring(WordToErase.NextWordStartLine)
            End If
            i = i - 1
            While i > 0
                LinePack.RemoveAt(WordToErase.Line + 1)
                i = i - 1
            End While
        End If
        Return WordsInLinePack(LinePack)

    End Function

    Public Function ReplaceWords(ByVal StartingWord As WordData, ByVal WordsList As List(Of WordData), ByVal LinePack As List(Of String), ByVal ParamArray NewWords As String()) As List(Of WordData)

        Dim lin As String
        Dim i As Integer
        Dim WordToErase As WordData
        Dim sbLin As Text.StringBuilder
        Dim linNew As String

        For i = 0 To NewWords.Length - 1
            WordToErase = WordsList(StartingWord.Index)
            WordsList = EraseWord(WordToErase, LinePack)
        Next
        lin = LinePack(StartingWord.Line)
        sbLin = New Text.StringBuilder(lin.Substring(0, StartingWord.Start))
        If StartingWord.Start > 0 Then
            If Not Char.IsWhiteSpace(lin.Chars(StartingWord.Start - 1)) Then
                sbLin.Append(" ")
            End If
        End If
        For Each linNew In NewWords
            sbLin.Append(linNew)
            sbLin.Append(" ")
        Next
        If StartingWord.Start < lin.Length Then
            If Char.IsWhiteSpace(lin.Chars(StartingWord.Start)) Then
                sbLin.Length = sbLin.Length - 1
            End If
        End If
        sbLin.Append(lin.Substring(StartingWord.Start))
        LinePack(StartingWord.Line) = sbLin.ToString
        Return WordsInLinePack(LinePack)

    End Function

    Private Function LoadSourceFile(ByVal SourceFile As String) As List(Of List(Of String))

        Dim LinesList As List(Of List(Of String))
        Dim lin As String
        Dim LinePack As List(Of String)

        LinesList = New List(Of List(Of String))
        LinePack = New List(Of String)
        Using fs = IO.File.OpenRead(SourceFile)
            Using sr = New IO.StreamReader(fs, System.Text.Encoding.Default)
                While Not sr.EndOfStream
                    lin = sr.ReadLine()
                    LinePack.Add(lin)
                    If Not lin.Trim.EndsWith("_") Then
                        LinesList.Add(LinePack)
                        LinePack = New List(Of String)
                    End If
                End While
            End Using
        End Using
        If LinePack.Count > 0 Then
            LinesList.Add(LinePack)
        End If
        Return LinesList

    End Function

    Private Sub SaveDestinationFile(ByVal LinesList As List(Of List(Of String)), ByVal DestinationFilename As String, ByVal SourceFile As String, ByVal SourcePath As String, ByVal DestinationPath As String, ByVal DoNotOverwrite As Boolean)

        Dim DestinationFile As String
        Dim i As Integer
        Dim LinePack As List(Of String)
        Dim lin As String
        Dim Proceed As Boolean

        i = SourcePath.Length
        While SourceFile.Chars(i) = IO.Path.DirectorySeparatorChar _
        OrElse SourceFile.Chars(i) = IO.Path.AltDirectorySeparatorChar
            i = i + 1
        End While
        DestinationFile = IO.Path.Combine(DestinationPath, SourceFile.Substring(i))
        i = DestinationFile.LastIndexOfAny(New Char() {IO.Path.DirectorySeparatorChar, IO.Path.AltDirectorySeparatorChar})
        DestinationFile = IO.Path.Combine(DestinationFile.Substring(0, i), DestinationFilename)
        IO.Directory.CreateDirectory(IO.Path.GetDirectoryName(DestinationFile))
        If DoNotOverwrite Then
            Proceed = Not IO.File.Exists(DestinationFile)
        Else
            Proceed = True
        End If
        If Proceed Then
            Using fs = IO.File.Create(DestinationFile)
                Using sw = New IO.StreamWriter(fs, System.Text.Encoding.Default)
                    For Each LinePack In LinesList
                        For Each lin In LinePack
                            sw.WriteLine(lin)
                        Next
                    Next
                End Using
            End Using
        End If

    End Sub

    Private Sub AddTextToLinePack(ByVal LinePack As List(Of String), ByVal NewText As String)

        Dim txt As String

        txt = ValidXMLText(NewText.Trim, True)
        AddLiteralToLinePack(LinePack, """" & RemoveStartEndQuotesFromValidXML(txt) & """")

    End Sub

    Private Sub AddLiteralToLinePack(ByVal LinePack As List(Of String), ByVal NewLiteral As String)

        If LinePack.Count = 0 Then
            LinePack.Add(NewLiteral.ToString)
        Else
            LinePack(LinePack.Count - 1) = LinePack(LinePack.Count - 1) & NewLiteral
        End If

    End Sub

    Private Sub AddScreenCoordToLinePack(ByVal LinePack As List(Of String), ByVal NewScreenCoord As String, ByVal AdditionalSpace As Integer)

        Dim c As Double

        c = Convert.ToInt32(NewScreenCoord, Globalization.CultureInfo.InvariantCulture)
        c = c / 15.0
        AddLiteralToLinePack(LinePack, Convert.ToString(Convert.ToInt32(c + AdditionalSpace), Globalization.CultureInfo.InvariantCulture))

    End Sub

    Private Function AddContentToDesignerLinesList(ByVal NewContent As String, ByVal DesignerLinesList As List(Of List(Of String)), ByVal ElementInfo As Dictionary(Of String, String), ByVal Location As Integer, ByVal TabCount As Integer, ByVal ResourceKey As String, ByVal CurrentElementType As String) As Integer

        Dim Underline As Boolean
        Dim Strikethrough As Boolean
        Dim LinePack As List(Of String)
        Dim AutoSize As Boolean
        Dim TabIncrement1 As Integer
        Dim TabIncrement2 As Integer

        Underline = ElementInfo.ContainsKey("Underline")
        Strikethrough = ElementInfo.ContainsKey("Strikethrough")
        LinePack = New List(Of String)
        If ElementInfo.ContainsKey("AutoSize") Then
            AutoSize = (Convert.ToInt32(ElementInfo("AutoSize"), Globalization.CultureInfo.InvariantCulture) <> 0)
        Else
            AutoSize = False
        End If
        If ElementInfo.ContainsKey("ContentCount") AndAlso Convert.ToInt32(ElementInfo("ContentCount"), Globalization.CultureInfo.InvariantCulture) > 1 Then
            TabIncrement1 = 1
        Else
            TabIncrement1 = 0
        End If
        LinePack.Add(TabSequence(TabCount + TabIncrement1) & "<TextBlock")
        If ResourceKey <> "" Then
            AddLiteralToLinePack(LinePack, " x:Key=")
            AddTextToLinePack(LinePack, ResourceKey)
        End If
        AddLiteralToLinePack(LinePack, " TextWrapping=""Wrap""")
        If ElementInfo.ContainsKey("ContentHorizontalAlignment") Then
            AddLiteralToLinePack(LinePack, " HorizontalAlignment=")
            AddTextToLinePack(LinePack, ElementInfo("ContentHorizontalAlignment"))
        End If
        If ElementInfo.ContainsKey("ContentVerticalAlignment") Then
            AddLiteralToLinePack(LinePack, " VerticalAlignment=")
            AddTextToLinePack(LinePack, ElementInfo("ContentVerticalAlignment"))
        End If
        If Not AutoSize _
        AndAlso CurrentElementType <> "VB.CHECKBOX" _
        AndAlso CurrentElementType <> "VB.OPTIONBUTTON" _
        AndAlso Not ElementInfo.ContainsKey("IsToolbarButton") Then
            AddLiteralToLinePack(LinePack, " Margin=""-5""")
        End If
        AddLiteralToLinePack(LinePack, ">")
        DesignerLinesList.Insert(Location, LinePack)
        Location = Location + 1
        If Underline And Strikethrough Then
            LinePack = New List(Of String)
            LinePack.Add(TabSequence(TabCount + TabIncrement1 + 1) & "<Run TextDecorations=""Underline,Strikethrough"">")
            DesignerLinesList.Insert(Location, LinePack)
            Location = Location + 1
            TabIncrement2 = 1
        ElseIf Underline Then
            LinePack = New List(Of String)
            LinePack.Add(TabSequence(TabCount + TabIncrement1 + 1) & "<Underline>")
            DesignerLinesList.Insert(Location, LinePack)
            Location = Location + 1
            TabIncrement2 = 1
        ElseIf Strikethrough Then
            LinePack = New List(Of String)
            LinePack.Add(TabSequence(TabCount + TabIncrement1 + 1) & "<Run TextDecorations=""Strikethrough"">")
            DesignerLinesList.Insert(Location, LinePack)
            Location = Location + 1
            TabIncrement2 = 1
        Else
            TabIncrement2 = 0
        End If
        LinePack = New List(Of String)
        LinePack.Add(TabSequence(TabCount + TabIncrement1 + TabIncrement2 + 1) & NewContent)
        DesignerLinesList.Insert(Location, LinePack)
        Location = Location + 1
        If Underline And Strikethrough Then
            LinePack = New List(Of String)
            LinePack.Add(TabSequence(TabCount + TabIncrement1 + 1) & "</Run>")
            DesignerLinesList.Insert(Location, LinePack)
            Location = Location + 1
        ElseIf Underline Then
            LinePack.Add(TabSequence(TabCount + TabIncrement1 + 1) & "</Underline>")
            DesignerLinesList.Insert(Location, LinePack)
            Location = Location + 1
        ElseIf Strikethrough Then
            LinePack.Add(TabSequence(TabCount + TabIncrement1 + 1) & "</Run>")
            DesignerLinesList.Insert(Location, LinePack)
            Location = Location + 1
        End If
        LinePack = New List(Of String)
        LinePack.Add(TabSequence(TabCount + TabIncrement1) & "</TextBlock>")
        DesignerLinesList.Insert(Location, LinePack)
        Location = Location + 1
        Return Location

    End Function

    Private Sub AddNameInfoToLinePack(ByVal LinePack As List(Of String), ByVal ElementNames As Dictionary(Of String, String), ByVal ElementFinalNames As Dictionary(Of String, String), ByVal ElementInfo As Dictionary(Of String, String))

        Dim s As String
        Dim i As Integer
        Dim num As String
        Dim UnderscoreSequence As String

        s = ElementInfo("Name")
        i = ElementNames(s).LastIndexOf(",")
        If i >= 0 Then
            num = ElementNames(s).Substring(i + 1)
        Else
            num = ElementNames(s)
        End If
        If num = "*" Then
            num = ""
        End If
        UnderscoreSequence = ""
        If Not ElementFinalNames.ContainsKey(s) Then
            While ElementFinalNames.ContainsValue(s & UnderscoreSequence & num)
                UnderscoreSequence = UnderscoreSequence & "_"
            End While
            ElementFinalNames.Add(s, s & UnderscoreSequence)
        End If
        If ElementInfo.ContainsKey("UseXName") Then
            AddLiteralToLinePack(LinePack, " x:Name=")
        Else
            AddLiteralToLinePack(LinePack, " Name=")
        End If
        If ElementInfo.ContainsKey("IsWindowsFormsHost") Then
            AddTextToLinePack(LinePack, s & "WindowsFormsHost" & UnderscoreSequence & num)
        Else
            AddTextToLinePack(LinePack, s & UnderscoreSequence & num)
        End If

    End Sub

    Private Sub AddMarginInfoToLinePack(ByVal LinePack As List(Of String), ByVal ElementInfo As Dictionary(Of String, String))

        If ElementInfo.ContainsKey("Left") AndAlso ElementInfo.ContainsKey("Top") Then
            AddLiteralToLinePack(LinePack, " HorizontalAlignment=""Left"" VerticalAlignment=""Top"" Margin=""")
            AddScreenCoordToLinePack(LinePack, ElementInfo("Left"), 0)
            AddLiteralToLinePack(LinePack, ",")
            AddScreenCoordToLinePack(LinePack, ElementInfo("Top"), 0)
            AddLiteralToLinePack(LinePack, ",0,0""")
        End If

    End Sub

    Private Sub AddSizeInfoToLinePack(ByVal LinePack As List(Of String), ByVal ElementInfo As Dictionary(Of String, String), ByVal CurrentElementType As String)

        Dim AddInfo As Boolean
        Dim FinalWidth As String
        Dim FinalHeight As String

        If ElementInfo.ContainsKey("AutoSize") Then
            AddInfo = (Convert.ToInt32(ElementInfo("AutoSize"), Globalization.CultureInfo.InvariantCulture) = 0)
        Else
            AddInfo = True
        End If
        If AddInfo Then
            If ElementInfo.ContainsKey("Width") Then
                FinalWidth = ElementInfo("Width")
            ElseIf ElementInfo.ContainsKey("ScaleWidth") Then
                FinalWidth = ElementInfo("ScaleWidth")
            Else
                FinalWidth = ""
            End If
            If ElementInfo.ContainsKey("Height") Then
                FinalHeight = ElementInfo("Height")
            ElseIf ElementInfo.ContainsKey("ScaleHeight") Then
                FinalHeight = ElementInfo("ScaleHeight")
            Else
                FinalHeight = ""
            End If
            If FinalWidth <> "" Then
                AddLiteralToLinePack(LinePack, " Width=""")
                AddScreenCoordToLinePack(LinePack, FinalWidth, 0)
                AddLiteralToLinePack(LinePack, """")
            End If
            If FinalHeight <> "" Then
                AddLiteralToLinePack(LinePack, " Height=""")
                AddScreenCoordToLinePack(LinePack, FinalHeight, 0)
                AddLiteralToLinePack(LinePack, """")
            End If
        ElseIf CurrentElementType = "VB.IMAGE" _
        OrElse CurrentElementType = "VB.PICTUREBOX" Then
            AddLiteralToLinePack(LinePack, " Stretch=""None""")
        End If

    End Sub

    Private Sub AddComboBoxStyleInfoToLinePack(ByVal LinePack As List(Of String), ByVal ElementInfo As Dictionary(Of String, String), ByVal ControlType As String)

        If ControlType = "VB.COMBOBOX" AndAlso ElementInfo.ContainsKey("Style") Then
            If Convert.ToInt32(ElementInfo("Style"), Globalization.CultureInfo.InvariantCulture) = 2 Then
                AddLiteralToLinePack(LinePack, " IsEditable=""False""")
            End If
        End If

    End Sub

    Private Sub SwitchIfPasswordBox(ByVal LinePack As List(Of String), ByVal ElementInfo As Dictionary(Of String, String), ByVal ControlType As String)

        If ControlType = "VB.TEXTBOX" AndAlso ElementInfo.ContainsKey("PasswordChar") AndAlso ElementInfo("PasswordChar").Trim.Replace("""", "") <> "" Then
            LinePack(0) = LinePack(0).Replace("<TextBox", "<PasswordBox")
            If ElementInfo("PasswordChar").Trim.Replace("""", "") <> "*" Then
                AddLiteralToLinePack(LinePack, " Password=")
                AddTextToLinePack(LinePack, ElementInfo("PasswordChar"))
            End If
        End If

    End Sub

    Private Function SwitchIfContextMenu(ByVal LinePack As List(Of String), ByVal ElementInfo As Dictionary(Of String, String), ByVal ControlType As String, ByVal ParentControlType As String, ByVal CommentsLinePack As List(Of String)) As Boolean

        Dim IsVisible As Boolean
        Dim IsContextMenu As Boolean

        IsVisible = Not (ElementInfo.ContainsKey("Visible") AndAlso Convert.ToInt32(ElementInfo("Visible"), Globalization.CultureInfo.InvariantCulture) = 0)
        If ParentControlType = "VB.MENU" Then
            IsContextMenu = False
        Else
            IsContextMenu = Not (ControlType = "VB.MENU" AndAlso ParentControlType = "VB.FORM" AndAlso IsVisible)
        End If
        If IsContextMenu Then
            LinePack(0) = LinePack(0).Replace("<MenuItem", "<ContextMenu x:Key=""" & ElementInfo("Name") & """")
            If ElementInfo.ContainsKey("MenuHeader") Then
                CommentsLinePack.Add("Header = " & ElementInfo("MenuHeader"))
            End If
        Else
            If Not IsVisible Then
                AddLiteralToLinePack(LinePack, " Visibility=""Collapsed""")
            End If
            If ElementInfo.ContainsKey("MenuHeader") Then
                AddLiteralToLinePack(LinePack, " Header=")
                AddTextToLinePack(LinePack, ElementInfo("MenuHeader"))
            End If
        End If
        Return IsContextMenu

    End Function

    Private Function CurrentContentCount(ByVal ElementInfo As Dictionary(Of String, String)) As Integer

        Dim c As Integer

        If ElementInfo.ContainsKey("ContentCount") Then
            c = Convert.ToInt32(ElementInfo("ContentCount"), Globalization.CultureInfo.InvariantCulture)
        Else
            c = 0
        End If
        Return c

    End Function

    Private Sub IncrementContentCount(ByVal ElementInfo As Dictionary(Of String, String))

        If ElementInfo.ContainsKey("ContentCount") Then
            ElementInfo("ContentCount") = Convert.ToString(Convert.ToInt32(ElementInfo("ContentCount"), Globalization.CultureInfo.InvariantCulture) + 1, Globalization.CultureInfo.InvariantCulture)
        Else
            ElementInfo.Add("ContentCount", "1")
        End If
        If Not ElementInfo.ContainsKey("EndElementBelow") Then
            ElementInfo.Add("EndElementBelow", "1")
        End If

    End Sub

    Private Function AddBackgroundInfoToLinePack(ByVal LinePack As List(Of String), ByVal ElementInfo As Dictionary(Of String, String), ByVal DesignerLinesList As List(Of List(Of String)), ByVal Location As Integer, ByVal TabCount As Integer, ByVal ControlType As String, ByVal TopLevelElement As String) As Integer

        Dim Opacity As String
        Dim BackgroundEnabled As Boolean
        Dim BackgroundImageEnabled As Boolean
        Dim ResourceFilename As String
        Dim ResourceLocation As String
        Dim NewLinePack As List(Of String)
        Dim TabIncrement As Integer

        If ElementInfo.ContainsKey("Opacity") Then
            Opacity = ElementInfo("Opacity")
        Else
            Opacity = "1"
        End If
        If Opacity = "1" AndAlso ElementInfo.ContainsKey("Background") AndAlso ElementInfo("Background").Trim.Replace("""", "") <> "" Then
            BackgroundEnabled = True
        End If
        If ElementInfo.ContainsKey("BackgroundImage") AndAlso ElementInfo("BackgroundImage").Trim.Replace("""", "") <> "" Then
            BackgroundImageEnabled = True
        End If
        If BackgroundImageEnabled Then
            ResourceFilename = ElementInfo("BackgroundImage").Substring(1, ElementInfo("BackgroundImage").LastIndexOf(":") - 1).Trim.Replace("""", "")
            ResourceFilename = IO.Path.GetFileNameWithoutExtension(ResourceFilename)
            ResourceLocation = ElementInfo("BackgroundImage").Substring(ElementInfo("BackgroundImage").LastIndexOf(":") + 1)
            If ControlType = "VB.FORM" _
            OrElse ControlType = "VB.USERCONTROL" _
            OrElse ControlType = "VB.USERDOCUMENT" Then
                NewLinePack = New List(Of String)
                NewLinePack.Add(TabSequence(TabCount) & "<" & TopLevelElement & ".Background>")
                DesignerLinesList.Insert(Location, NewLinePack)
                Location = Location + 1
                NewLinePack = New List(Of String)
                NewLinePack.Add(TabSequence(TabCount + 1) & "<ImageBrush ImageSource=""{StaticResource " & ResourceFilename & "ResourceAt" & ResourceLocation & "}""/>")
                DesignerLinesList.Insert(Location, NewLinePack)
                Location = Location + 1
                NewLinePack = New List(Of String)
                NewLinePack.Add(TabSequence(TabCount) & "</" & TopLevelElement & ".Background>")
                DesignerLinesList.Insert(Location, NewLinePack)
                Location = Location + 1
            ElseIf ControlType = "VB.FRAME" _
            OrElse ControlType = "VB.CHECKBOX" _
            OrElse ControlType = "VB.COMMANDBUTTON" _
            OrElse ControlType = "VB.LABEL" _
            OrElse ControlType = "VB.TEXTBOX" _
            OrElse ControlType = "VB.LISTBOX" _
            OrElse ControlType = "VB.IMAGE" _
            OrElse ControlType = "VB.COMBOBOX" _
            OrElse ControlType = "VB.PICTUREBOX" _
            OrElse ControlType = "VB.OPTIONBUTTON" _
            OrElse ControlType = "RICHTEXTLIB.RICHTEXTBOX" _
            OrElse ControlType = "COMCTLLIB.PROGRESSBAR" _
            OrElse ControlType = "MSCOMCTLLIB.PROGRESSBAR" _
            OrElse ControlType = "COMCTLLIB.LISTVIEW" _
            OrElse ControlType = "MSCOMCTLLIB.LISTVIEW" _
            OrElse ControlType = "COMCTLLIB.TOOLBAR" _
            OrElse ControlType = "MSCOMCTLLIB.TOOLBAR" _
            OrElse ControlType = "COMCTLLIB.STATUSBAR" _
            OrElse ControlType = "MSCOMCTLLIB.STATUSBAR" _
            OrElse ControlType = "COMCTLLIB.TREEVIEW" _
            OrElse ControlType = "MSCOMCTLLIB.TREEVIEW" Then
                If ElementInfo.ContainsKey("ContentCount") AndAlso Convert.ToInt32(ElementInfo("ContentCount"), Globalization.CultureInfo.InvariantCulture) > 1 Then
                    TabIncrement = 1
                Else
                    TabIncrement = 0
                End If
                NewLinePack = New List(Of String)
                NewLinePack.Add(TabSequence(TabCount + TabIncrement) & "<Image Source=""{StaticResource " & ResourceFilename & "ResourceAt" & ResourceLocation & "}"" />")
                DesignerLinesList.Insert(Location, NewLinePack)
                Location = Location + 1
            Else
                AddLiteralToLinePack(LinePack, " Picture=")
                AddTextToLinePack(LinePack, ElementInfo("BackgroundImage"))
            End If
        ElseIf BackgroundEnabled Then
            AddLiteralToLinePack(LinePack, " Background=""")
            AddLiteralToLinePack(LinePack, ConvertColor(ElementInfo("Background")))
            AddLiteralToLinePack(LinePack, """")
        End If
        Return Location

    End Function

    Private Sub AddButtonSizeInfoToLinePack(ByVal LinePack As List(Of String), ByVal ElementInfo As Dictionary(Of String, String))

        If ElementInfo.ContainsKey("ButtonWidth") Then
            AddLiteralToLinePack(LinePack, " Width=""")
            AddScreenCoordToLinePack(LinePack, ElementInfo("ButtonWidth"), 0)
            AddLiteralToLinePack(LinePack, """")
        End If
        If ElementInfo.ContainsKey("ButtonHeight") Then
            AddLiteralToLinePack(LinePack, " Height=""")
            AddScreenCoordToLinePack(LinePack, ElementInfo("ButtonHeight"), 0)
            AddLiteralToLinePack(LinePack, """")
        End If

    End Sub

    Private Function AddToolbarImageInfoToLinePack(ByVal ElementInfo As Dictionary(Of String, String), ByVal DesignerLinesList As List(Of List(Of String)), ByVal Location As Integer, ByVal TabCount As Integer) As Integer

        Dim TabIncrement As Integer
        Dim LinePack As List(Of String)

        If ElementInfo.ContainsKey("ToolbarImage") Then
            If ElementInfo.ContainsKey("ContentCount") AndAlso Convert.ToInt32(ElementInfo("ContentCount"), Globalization.CultureInfo.InvariantCulture) > 1 Then
                TabIncrement = 1
            Else
                TabIncrement = 0
            End If
            LinePack = New List(Of String)
            LinePack.Add(TabSequence(TabCount + TabIncrement) & "<Image HorizontalAlignment=""Center"" VerticalAlignment=""Center"" Stretch=""None"" Source=""{StaticResource " & ElementInfo("ToolbarImage") & "}"" />")
            DesignerLinesList.Insert(Location, LinePack)
            Location = Location + 1
        End If
        Return Location

    End Function

    Private Function AddActiveXNamespacesToLinePack(ByVal LinePack As List(Of String), ByVal ActiveXControlList As List(Of String), ByVal Location As Integer, ByVal TabCount As Integer) As Integer

        Dim ax As String
        Dim i As Integer
        Dim axNamespace As String
        Dim j As Integer
        Dim axData As ActiveXControlData

        If ActiveXControlList.Count > 0 Then
            LinePack.Insert(Location, TabSequence(TabCount) & "xmlns:wf=""clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms""")
            Location = Location + 1
            j = 1
            For Each ax In ActiveXControlList
                i = ax.IndexOf(".")
                If i > 0 Then
                    axNamespace = ax.Substring(0, i)
                Else
                    axNamespace = ax
                End If
                axData = New ActiveXControlData
                axData.ControlNamespace = axNamespace
                axData.ControlAssembly = axNamespace
                ActiveXCleanup.CleanupNamespaces(axData)
                If j = 1 Then
                    LinePack.Insert(Location, TabSequence(TabCount) & "xmlns:ax=""clr-namespace:Ax" & axData.ControlNamespace & ";assembly=Ax" & axData.ControlAssembly & """")
                Else
                    LinePack.Insert(Location, TabSequence(TabCount) & "xmlns:ax" & j & "=""clr-namespace:Ax" & axData.ControlNamespace & ";assembly=Ax" & axData.ControlAssembly & """")
                End If
                Location = Location + 1
                j = j + 1
            Next
        End If
        Return Location

    End Function

    Private Sub AddResourceNamespacesToLinePack(ByVal LinePack As List(Of String), ByVal ResourceList As Dictionary(Of String, ResourceData), ByVal Location As Integer, ByVal TabCount As Integer)

        If ResourceList.Count > 0 Then
            LinePack.Insert(Location, TabSequence(TabCount) & "xmlns:System=""clr-namespace:System;assembly=mscorlib""")
        End If

    End Sub

    Private Function AddContentStartInfoToLinePack(ByVal ElementInfo As Dictionary(Of String, String), ByVal TabCount As Integer, ByVal DesignerLinesList As List(Of List(Of String)), ByVal Location As Integer) As Integer

        Dim LinePack As List(Of String)

        If ElementInfo.ContainsKey("ContentCount") AndAlso Convert.ToInt32(ElementInfo("ContentCount"), Globalization.CultureInfo.InvariantCulture) > 1 Then
            LinePack = New List(Of String)
            If ElementInfo.ContainsKey("IsToolbarButton") Then
                If ElementInfo.ContainsKey("TextAlignment") AndAlso Convert.ToInt32(ElementInfo("TextAlignment"), Globalization.CultureInfo.InvariantCulture) = 1 Then
                    LinePack.Add(TabSequence(TabCount) & "<StackPanel Orientation=""Horizontal"">")
                Else
                    LinePack.Add(TabSequence(TabCount) & "<StackPanel Orientation=""Vertical"">")
                End If
            Else
                LinePack.Add(TabSequence(TabCount) & "<Grid>")
            End If
            DesignerLinesList.Insert(Location, LinePack)
            Location = Location + 1
        End If
        Return Location

    End Function

    Private Function AddContentInfoToLinePack(ByVal LinePack As List(Of String), ByVal ElementInfo As Dictionary(Of String, String), ByVal TabCount As Integer, ByVal DesignerLinesList As List(Of List(Of String)), ByVal Location As Integer, ByVal CurrentElementType As String) As Integer

        Dim txt As String
        Dim LineEnded As Boolean

        If ElementInfo.ContainsKey("Content") Then
            If ElementInfo("Content").Trim.StartsWith("{") Then
                If LinePack(LinePack.Count - 1).EndsWith(">") Then
                    LineEnded = True
                    LinePack(LinePack.Count - 1) = LinePack(LinePack.Count - 1).Substring(0, LinePack(LinePack.Count - 1).Length - 1)
                End If
                AddLiteralToLinePack(LinePack, " Content=")
                AddTextToLinePack(LinePack, ElementInfo("Content"))
                If LineEnded Then
                    AddLiteralToLinePack(LinePack, ">")
                End If
            Else
                txt = RemoveStartEndQuotesFromValidXML(ValidXMLText(ElementInfo("Content"), True))
                If txt.Trim <> "" Then
                    Location = AddContentToDesignerLinesList(txt, DesignerLinesList, ElementInfo, Location, TabCount, "", CurrentElementType)
                End If
            End If
        End If
        Return Location

    End Function

    Private Function AddContentEndInfoToLinePack(ByVal ElementInfo As Dictionary(Of String, String), ByVal TabCount As Integer, ByVal DesignerLinesList As List(Of List(Of String)), ByVal Location As Integer) As Integer

        Dim LinePack As List(Of String)

        If ElementInfo.ContainsKey("ContentCount") AndAlso Convert.ToInt32(ElementInfo("ContentCount"), Globalization.CultureInfo.InvariantCulture) > 1 Then
            LinePack = New List(Of String)
            If ElementInfo.ContainsKey("IsToolbarButton") Then
                LinePack.Add(TabSequence(TabCount) & "</StackPanel>")
            Else
                LinePack.Add(TabSequence(TabCount) & "</Grid>")
            End If
            DesignerLinesList.Insert(Location, LinePack)
            Location = Location + 1
        End If
        Return Location

    End Function

    Private Function ReadTextFromLine(ByVal Line As String, ByVal WordsList As List(Of WordData), ByVal Location As Integer, ByVal ToEndOfLine As Boolean, ByVal ResourceList As Dictionary(Of String, ResourceData), ByVal ElementInfo As Dictionary(Of String, String), ByVal ElementInfoKey As String, ByVal CheckEndingTag As Boolean) As String

        Dim lin As String
        Dim linTrim As String
        Dim ResourceFilename As String
        Dim ResourceLocation As String
        Dim res As ResourceData
        Dim IsReferenceToResource As Boolean
        Dim Start As Integer

        If ToEndOfLine Then
            lin = Line.Substring(WordsList(Location).Start)
        Else
            lin = Line.Substring(WordsList(Location).Start, WordsList(Location).Word.Length)
        End If
        If ResourceList IsNot Nothing Then
            linTrim = lin.Trim
            IsReferenceToResource = linTrim.StartsWith("$""")
            If IsReferenceToResource Then
                Start = 1
            Else
                Start = 0
            End If
            If CheckEndingTag Then
                IsReferenceToResource = IsReferenceToResource OrElse linTrim.IndexOf(""":") > 0
            End If
            If IsReferenceToResource Then
                ResourceFilename = linTrim.Substring(Start, linTrim.LastIndexOf(":") - 1).Trim.Replace("""", "")
                ResourceFilename = IO.Path.GetFileNameWithoutExtension(ResourceFilename)
                ResourceLocation = linTrim.Substring(lin.LastIndexOf(":") + 1)
                lin = "{StaticResource " & ResourceFilename & "ResourceAt" & ResourceLocation & "}"
                res = New ResourceData
                res.Type = "String"
                res.ElementInfo = ElementInfo
                ResourceList.Add(ResourceLocation, res)
                If ElementInfoKey <> "" Then
                    ElementInfo.Add(ElementInfoKey, ResourceLocation)
                End If
            End If
        End If
        Return lin

    End Function

    Private Sub AddTopLevelInfoToLinePack(ByVal LinePack As List(Of String), ByVal ElementInfo As Dictionary(Of String, String), ByVal CurrentElementType As String)

        Dim BorderStyle As Integer
        Dim MaxButton As Integer
        Dim MinButton As Integer

        If CurrentElementType = "VB.FORM" Then
            If ElementInfo.ContainsKey("BorderStyle") Then
                BorderStyle = Convert.ToInt32(ElementInfo("BorderStyle"), Globalization.CultureInfo.InvariantCulture)
            Else
                BorderStyle = 2
            End If
            If ElementInfo.ContainsKey("MaxButton") Then
                MaxButton = Convert.ToInt32(ElementInfo("MaxButton"), Globalization.CultureInfo.InvariantCulture)
            Else
                MaxButton = 1
            End If
            If ElementInfo.ContainsKey("MinButton") Then
                MinButton = Convert.ToInt32(ElementInfo("MinButton"), Globalization.CultureInfo.InvariantCulture)
            Else
                MinButton = 1
            End If
            Select Case BorderStyle
                Case 0
                    AddLiteralToLinePack(LinePack, " WindowStyle=""None"" ResizeMode=""NoResize""")
                Case 1
                    AddLiteralToLinePack(LinePack, " WindowStyle=""SingleBorderWindow""")
                    If MinButton > 0 Then
                        AddLiteralToLinePack(LinePack, " ResizeMode=""CanMinimize""")
                    Else
                        AddLiteralToLinePack(LinePack, " ResizeMode=""NoResize""")
                    End If
                Case 2
                    AddLiteralToLinePack(LinePack, " WindowStyle=""SingleBorderWindow""")
                    If MinButton > 0 OrElse MaxButton > 0 Then
                        AddLiteralToLinePack(LinePack, " ResizeMode=""CanResizeWithGrip""")
                    Else
                        AddLiteralToLinePack(LinePack, " ResizeMode=""NoResize""")
                    End If
                Case 3
                    AddLiteralToLinePack(LinePack, " WindowStyle=""SingleBorderWindow"" ResizeMode=""NoResize""")
                Case 4
                    AddLiteralToLinePack(LinePack, " WindowStyle=""ToolWindow"" ResizeMode=""NoResize""")
                Case 5
                    AddLiteralToLinePack(LinePack, " WindowStyle=""ToolWindow"" ResizeMode=""CanResizeWithGrip""")
            End Select
        End If

    End Sub

    Private Sub AddCommentsToDesignerLinesList(ByVal CommentsLinePack As List(Of String), ByVal DesignerLinesList As List(Of List(Of String)), ByVal Location As Integer, ByVal TabCount As Integer)

        Dim NewLinePack As List(Of String)
        Dim i As Integer

        If CommentsLinePack.Count > 0 Then
            CommentsLinePack.Insert(0, "<!--")
            CommentsLinePack.Add("-->")
            For i = 0 To CommentsLinePack.Count - 1
                NewLinePack = New List(Of String)
                If i = 0 OrElse i = CommentsLinePack.Count - 1 Then
                    NewLinePack.Add(TabSequence(TabCount) & CommentsLinePack(i))
                Else
                    NewLinePack.Add(TabSequence(TabCount + 1) & CommentsLinePack(i))
                End If
                DesignerLinesList.Insert(Location, NewLinePack)
                Location = Location + 1
            Next
        End If

    End Sub

    Private Sub AddElementEnding(ByVal elm As String, ByVal DesignerLinesList As List(Of List(Of String)), ByVal TabCount As Integer, ByVal ElementInfo As Dictionary(Of String, String))

        Dim LinePack As List(Of String)

        If ElementInfo.ContainsKey("EndElementBelow") AndAlso ElementInfo("EndElementBelow") = "1" Then
            LinePack = New List(Of String)
            LinePack.Add(TabSequence(TabCount) & "</" & elm & ">")
            DesignerLinesList.Add(LinePack)
        Else
            LinePack = DesignerLinesList(DesignerLinesList.Count - 1)
            AddLiteralToLinePack(LinePack, "</" & elm & ">")
        End If

    End Sub

    Private Function AddResourcesToDesigner(ByVal DesignerLinesList As List(Of List(Of String)), ByVal ResourceList As Dictionary(Of String, ResourceData), ByVal AdditionalResources As List(Of List(Of String)), ByVal ResourceFile As String, ByVal SourcePath As String, ByVal DestinationPath As String, ByVal Location As Integer, ByVal TabCount As Integer, ByVal ElementInfo As Dictionary(Of String, String), ByVal TopLevelElement As String, ByVal CurrentElementType As String) As Integer

        Dim LinePack As List(Of String)
        Dim res As KeyValuePair(Of String, ResourceData)
        Dim ResourceLocations As SortedDictionary(Of Integer, String)
        Dim ResourceLengths As SortedDictionary(Of Integer, Integer)
        Dim i As Integer
        Dim dat As Byte()
        Dim ResourceFilename As String
        Dim j As Integer
        Dim n As Integer
        Dim sb As Text.StringBuilder
        Dim DestinationFile As String
        Dim ImageExtension As String
        Dim ResourceType As String
        Dim resLocation As Integer
        Dim lin As String
        Dim NewLinePack As List(Of String)
        Dim ContainsEscapeChars As Boolean
        Dim FinalString As String
        Dim ImageResourceKey As String

        If ResourceList.Count > 0 OrElse AdditionalResources.Count > 0 Then
            If ResourceList.Count > 0 Then
                Using fs = IO.File.OpenRead(ResourceFile)
                    ReDim dat(fs.Length - 1)
                    fs.Read(dat, 0, fs.Length)
                End Using
                ResourceLocations = New SortedDictionary(Of Integer, String)
                ResourceLengths = New SortedDictionary(Of Integer, Integer)
                For Each res In ResourceList
                    ResourceLocations.Add(CLng("&H" & res.Key), res.Key)
                Next
                For i = 0 To ResourceLocations.Count - 1
                    If i = ResourceLocations.Count - 1 Then
                        ResourceLengths.Add(ResourceLocations.Keys(i), dat.Length - ResourceLocations.Keys(i))
                    Else
                        ResourceLengths.Add(ResourceLocations.Keys(i), ResourceLocations.Keys(i + 1) - ResourceLocations.Keys(i))
                    End If
                Next
                ResourceFilename = IO.Path.GetFileNameWithoutExtension(ResourceFile)
                LinePack = New List(Of String)
                LinePack.Add(TabSequence(TabCount) & "<" & TopLevelElement & ".Resources>")
                DesignerLinesList.Insert(Location, LinePack)
                Location = Location + 1
                For Each res In ResourceList
                    resLocation = CLng("&H" & res.Key)
                    ResourceType = res.Value.Type
                    If res.Value.ElementInfo IsNot Nothing AndAlso res.Value.ElementInfo.ContainsKey("ContentLocation") AndAlso res.Value.ElementInfo("ContentLocation") = ResourceLocations(resLocation) Then
                        ResourceType = "Content"
                    End If
                    If ResourceType = "String" Then
                        If dat.Length <= 256 Then
                            j = resLocation + 1
                            n = ResourceLengths(resLocation) - 1
                        Else
                            j = resLocation + 4
                            n = ResourceLengths(resLocation) - 4
                        End If
                        While j < n AndAlso dat(j) = 0
                            j = j + 1
                            n = n - 1
                        End While
                        ContainsEscapeChars = False
                        sb = New Text.StringBuilder
                        While n > 0
                            If dat(j) < 32 Then
                                ContainsEscapeChars = True
                            End If
                            sb.Append(ChrW(dat(j)))
                            j = j + 1
                            n = n - 1
                        End While
                        FinalString = sb.ToString
                        If FinalString = "" Then
                            LinePack = New List(Of String)
                            LinePack.Add(TabSequence(TabCount + 1) & "<x:Static x:Key=""" & ResourceFilename & "ResourceAt" & ResourceLocations(resLocation) & """ Member=""System: String.Empty"" />")
                        Else
                            LinePack = New List(Of String)
                            LinePack.Add(TabSequence(TabCount + 1) & "<System:String x:Key=""" & ResourceFilename & "ResourceAt" & ResourceLocations(resLocation) & """>")
                            If ContainsEscapeChars AndAlso FinalString.Contains("(Format)") AndAlso FinalString.Contains("(Text)") Then
                                AddLiteralToLinePack(LinePack, FormatStringText(sb.ToString))
                            Else
                                AddLiteralToLinePack(LinePack, ValidXMLText(sb.ToString, False))
                            End If
                            AddLiteralToLinePack(LinePack, "</System:String>")
                        End If
                        DesignerLinesList.Insert(Location, LinePack)
                        Location = Location + 1
                        If ContainsEscapeChars AndAlso FinalString.Contains("(Format)") AndAlso FinalString.Contains("(Text)") Then
                            LinePack = New List(Of String)
                            AddLiteralToLinePack(LinePack, TabSequence(TabCount + 1) & "<!-- Original: " & ValidXMLText(sb.ToString, False) & " -->")
                            DesignerLinesList.Insert(Location, LinePack)
                            Location = Location + 1
                        End If
                    ElseIf ResourceType = "Content" Then
                        j = resLocation + 4
                        n = ResourceLengths(resLocation) - 4
                        sb = New Text.StringBuilder
                        While n > 0
                            sb.Append(ChrW(dat(j)))
                            j = j + 1
                            n = n - 1
                        End While
                        Location = AddContentToDesignerLinesList(ValidXMLText(sb.ToString, False), DesignerLinesList, res.Value.ElementInfo, Location, TabCount + 1, ResourceFilename & "ResourceAt" & ResourceLocations(resLocation), CurrentElementType)
                    ElseIf ResourceType = "Image" Then
                        If ContainsData(dat, resLocation + 12, 16, AscW("K"c), &HB8, AscW("Q"c), AscW("l"c), AscW("t"c)) Then
                            j = resLocation + 28
                            n = ResourceLengths(resLocation) - 28
                        Else
                            j = resLocation + 12
                            n = ResourceLengths(resLocation) - 12
                        End If
                        i = SourcePath.Length
                        While ResourceFile.Chars(i) = IO.Path.DirectorySeparatorChar _
                        OrElse ResourceFile.Chars(i) = IO.Path.AltDirectorySeparatorChar
                            i = i + 1
                        End While
                        DestinationFile = IO.Path.Combine(DestinationPath, ResourceFile.Substring(i))
                        i = DestinationFile.LastIndexOfAny(New Char() {IO.Path.DirectorySeparatorChar, IO.Path.AltDirectorySeparatorChar})
                        If dat(j) = AscW("B"c) AndAlso dat(j + 1) = AscW("M"c) Then
                            ImageExtension = ".bmp"
                        ElseIf dat(j) = AscW("G"c) AndAlso dat(j + 1) = AscW("I"c) AndAlso dat(j + 2) = AscW("F"c) Then
                            ImageExtension = ".gif"
                        ElseIf dat(j) = &HFF AndAlso dat(j + 1) = &HD8 AndAlso ContainsData(dat, j + 2, 32, AscW("J"c), AscW("F"c), AscW("I"c), AscW("F"c)) Then
                            ImageExtension = ".jpg"
                        ElseIf dat(j) = 137 AndAlso dat(j + 1) = 80 AndAlso dat(j + 2) = 78 AndAlso dat(j + 3) = 71 AndAlso dat(j + 4) = 13 AndAlso dat(j + 5) = 10 AndAlso dat(j + 6) = 26 AndAlso dat(j + 7) = 10 Then
                            ImageExtension = ".png"
                        Else
                            ImageExtension = ".ico"
                        End If
                        DestinationFile = IO.Path.Combine(DestinationFile.Substring(0, i), ResourceFilename & "ResourceAt" & ResourceLocations(resLocation) & ImageExtension)
                        IO.Directory.CreateDirectory(IO.Path.GetDirectoryName(DestinationFile))
                        Using fs = IO.File.Create(DestinationFile)
                            fs.Write(dat, j, n)
                        End Using
                        LinePack = New List(Of String)
                        If res.Value.ElementInfo IsNot Nothing AndAlso res.Value.ElementInfo.ContainsKey("ImageListName") Then
                            ImageResourceKey = res.Value.ElementInfo("ImageListName") & "_"
                            If res.Value.ElementInfo.ContainsKey("Key") AndAlso res.Value.ElementInfo("Key").Replace("""", "").Trim <> "" Then
                                ImageResourceKey = ImageResourceKey & RemoveStartEndQuotesFromValidXML(ValidXMLText(res.Value.ElementInfo("Key"), True))
                            Else
                                ImageResourceKey = ImageResourceKey & res.Value.ElementInfo("ImageListIndex")
                            End If
                        Else
                            ImageResourceKey = ResourceFilename & "ResourceAt" & ResourceLocations(resLocation)
                        End If
                        LinePack.Add(TabSequence(TabCount + 1) & "<ImageSource x:Key=""" & ImageResourceKey & """>")
                        AddLiteralToLinePack(LinePack, ResourceFilename & "ResourceAt" & ResourceLocations(resLocation) & ImageExtension)
                        AddLiteralToLinePack(LinePack, "</ImageSource>")
                        DesignerLinesList.Insert(Location, LinePack)
                        Location = Location + 1
                    Else
                        LinePack = New List(Of String)
                        LinePack.Add(TabSequence(TabCount + 1) & "<!-- Location: " & ResourceLocations(resLocation) & ", Type: " & res.Value.Type & " -->")
                        DesignerLinesList.Insert(Location, LinePack)
                        Location = Location + 1
                    End If
                Next
            Else
                LinePack = New List(Of String)
                LinePack.Add(TabSequence(TabCount) & "<" & TopLevelElement & ".Resources>")
                DesignerLinesList.Insert(Location, LinePack)
                Location = Location + 1
            End If
            For Each LinePack In AdditionalResources
                NewLinePack = New List(Of String)
                For Each lin In LinePack
                    NewLinePack.Add(lin)
                Next
                DesignerLinesList.Insert(Location, NewLinePack)
                Location = Location + 1
            Next
            LinePack = New List(Of String)
            LinePack.Add(TabSequence(TabCount) & "</" & TopLevelElement & ".Resources>")
            DesignerLinesList.Insert(Location, LinePack)
            Location = Location + 1
        End If
        Return Location

    End Function

    Private Function ReadDesignerElement(ByVal i As Integer, ByVal DesignerLinesList As List(Of List(Of String)), ByVal LinesList As List(Of List(Of String)), ByVal CurrentLinePack As List(Of String), ByVal ElementInfo As Dictionary(Of String, String), ByVal CommentsToAddLinePack As List(Of String), ByVal CurrentElementType As String, ByVal TabCount As Integer, ByVal PropertyName As String, ByVal ElementNames As Dictionary(Of String, String), ByVal ElementFinalNames As Dictionary(Of String, String), ByVal IsActiveXControl As Boolean, ByVal ActiveXControlList As List(Of String), ByVal ResourceList As Dictionary(Of String, ResourceData), ByVal AdditionalResources As List(Of List(Of String)), ByVal ResourceFile As String, ByVal SourcePath As String, ByVal DestinationPath As String, ByVal TopLevelElement As String, ByVal Menu As MenuData) As Integer

        Dim LinePack As List(Of String)
        Dim WordsList As List(Of WordData)
        Dim NewLinePack As List(Of String)
        Dim InnerLinePack As List(Of String)
        Dim TabAdjust As Integer
        Dim CommentsLinePack As List(Of String)
        Dim ElementInfoToUse As Dictionary(Of String, String)
        Dim ActiveXControlListToUse As List(Of String)
        Dim Finished As Boolean
        Dim j As Integer
        Dim lin As String
        Dim elm As String
        Dim IsActiveXControlInUse As Boolean
        Dim CurrentElementIsActiveXControl As Boolean
        Dim k As Integer
        Dim axNamespace As String
        Dim ax As String
        Dim LinePackToUse As List(Of String)
        Dim NewValue As String
        Dim ResourceListToUse As Dictionary(Of String, ResourceData)
        Dim res As ResourceData
        Dim ResourceFilename As String
        Dim ResourceLocation As String
        Dim MenuLocation As Integer
        Dim IsContextMenu As Boolean
        Dim l As Integer
        Dim PropertyRecognized As Boolean

        Finished = False
        While (Not Finished) AndAlso (i < LinesList.Count)
            LinePack = LinesList(i)
            lin = LinePack(0)
            WordsList = WordsInLinePack(LinePack)
            If WordsList(0).Word = "BEGIN" Then
                NewLinePack = New List(Of String)
                InnerLinePack = New List(Of String)
                CommentsLinePack = New List(Of String)
                elm = ReadTextFromLine(lin, WordsList, 2, True, Nothing, Nothing, "", False).Trim
                If ElementNames.ContainsKey(elm) Then
                    ElementNames(elm) = ElementNames(elm) & ",*"
                Else
                    ElementNames.Add(elm, "*")
                End If
                ElementInfoToUse = New Dictionary(Of String, String)
                ElementInfoToUse.Add("Name", elm)
                TabAdjust = 1
                IsActiveXControlInUse = IsActiveXControl
                CurrentElementIsActiveXControl = False
                ActiveXControlListToUse = Nothing
                k = -1
                ax = ""
                ResourceListToUse = ResourceList
                MenuLocation = -1
                IsContextMenu = False
                If WordsList(1).Word = "VB.FORM" Then
                    NewLinePack.Add(TabSequence(TabCount) & "<Window x:Class=""" & elm & """")
                    NewLinePack.Add(TabSequence(TabCount + 1) & "xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""")
                    NewLinePack.Add(TabSequence(TabCount + 1) & "xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""")
                    k = NewLinePack.Count
                    NewLinePack.Add(TabSequence(TabCount + 1))
                    DesignerLinesList.Add(NewLinePack)
                    InnerLinePack.Add(TabSequence(TabCount + 1) & "<Grid>")
                    DesignerLinesList.Add(InnerLinePack)
                    TabAdjust = TabAdjust + 1
                    ActiveXControlListToUse = New List(Of String)
                    ResourceListToUse = New Dictionary(Of String, ResourceData)
                    AdditionalResources = New List(Of List(Of String))
                    Menu = New MenuData
                    Menu.BeginningLine = -1
                    Menu.EndingLine = -1
                    ElementInfoToUse.Add("EndElementBelow", "1")
                ElseIf WordsList(1).Word = "VB.USERCONTROL" _
                OrElse WordsList(1).Word = "VB.USERDOCUMENT" Then
                    NewLinePack.Add(TabSequence(TabCount) & "<UserControl x:Class=""" & elm & """")
                    NewLinePack.Add(TabSequence(TabCount + 1) & "xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""")
                    NewLinePack.Add(TabSequence(TabCount + 1) & "xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""")
                    k = NewLinePack.Count
                    NewLinePack.Add(TabSequence(TabCount + 1))
                    DesignerLinesList.Add(NewLinePack)
                    InnerLinePack.Add(TabSequence(TabCount + 1) & "<Grid>")
                    DesignerLinesList.Add(InnerLinePack)
                    TabAdjust = TabAdjust + 1
                    ActiveXControlListToUse = New List(Of String)
                    ResourceListToUse = New Dictionary(Of String, ResourceData)
                    AdditionalResources = New List(Of List(Of String))
                    ElementInfoToUse.Add("EndElementBelow", "1")
                ElseIf WordsList(1).Word = "VB.FRAME" AndAlso (Not IsActiveXControl) Then
                    NewLinePack.Add(TabSequence(TabCount) & "<GroupBox")
                    DesignerLinesList.Add(NewLinePack)
                    InnerLinePack.Add(TabSequence(TabCount + 1) & "<Grid>")
                    DesignerLinesList.Add(InnerLinePack)
                    TabAdjust = TabAdjust + 1
                    ElementInfoToUse.Add("EndElementBelow", "1")
                ElseIf WordsList(1).Word = "VB.CHECKBOX" AndAlso (Not IsActiveXControl) Then
                    NewLinePack.Add(TabSequence(TabCount) & "<CheckBox")
                    DesignerLinesList.Add(NewLinePack)
                ElseIf WordsList(1).Word = "VB.COMMANDBUTTON" AndAlso (Not IsActiveXControl) Then
                    NewLinePack.Add(TabSequence(TabCount) & "<Button")
                    DesignerLinesList.Add(NewLinePack)
                ElseIf WordsList(1).Word = "VB.LABEL" AndAlso (Not IsActiveXControl) Then
                    NewLinePack.Add(TabSequence(TabCount) & "<Label")
                    DesignerLinesList.Add(NewLinePack)
                ElseIf WordsList(1).Word = "VB.TEXTBOX" AndAlso (Not IsActiveXControl) Then
                    NewLinePack.Add(TabSequence(TabCount) & "<TextBox")
                    DesignerLinesList.Add(NewLinePack)
                ElseIf WordsList(1).Word = "VB.LISTBOX" AndAlso (Not IsActiveXControl) Then
                    NewLinePack.Add(TabSequence(TabCount) & "<ListBox")
                    DesignerLinesList.Add(NewLinePack)
                ElseIf WordsList(1).Word = "VB.IMAGE" AndAlso (Not IsActiveXControl) Then
                    NewLinePack.Add(TabSequence(TabCount) & "<Image")
                    DesignerLinesList.Add(NewLinePack)
                ElseIf WordsList(1).Word = "VB.COMBOBOX" AndAlso (Not IsActiveXControl) Then
                    NewLinePack.Add(TabSequence(TabCount) & "<ComboBox")
                    DesignerLinesList.Add(NewLinePack)
                ElseIf WordsList(1).Word = "VB.PICTUREBOX" AndAlso (Not IsActiveXControl) Then
                    NewLinePack.Add(TabSequence(TabCount) & "<Image")
                    DesignerLinesList.Add(NewLinePack)
                ElseIf WordsList(1).Word = "VB.OPTIONBUTTON" AndAlso (Not IsActiveXControl) Then
                    NewLinePack.Add(TabSequence(TabCount) & "<RadioButton")
                    DesignerLinesList.Add(NewLinePack)
                ElseIf WordsList(1).Word = "VB.MENU" AndAlso (Not IsActiveXControl) Then
                    MenuLocation = DesignerLinesList.Count
                    NewLinePack.Add(TabSequence(TabCount) & "<MenuItem")
                    DesignerLinesList.Add(NewLinePack)
                    ElementInfoToUse.Add("EndElementBelow", "1")
                ElseIf WordsList(1).Word = "RICHTEXTLIB.RICHTEXTBOX" AndAlso (Not IsActiveXControl) Then
                    NewLinePack.Add(TabSequence(TabCount) & "<RichTextBox")
                    DesignerLinesList.Add(NewLinePack)
                ElseIf (WordsList(1).Word = "COMCTLLIB.PROGRESSBAR" _
                OrElse WordsList(1).Word = "MSCOMCTLLIB.PROGRESSBAR") _
                AndAlso (Not IsActiveXControl) Then
                    NewLinePack.Add(TabSequence(TabCount) & "<ProgressBar")
                    DesignerLinesList.Add(NewLinePack)
                ElseIf (WordsList(1).Word = "COMCTLLIB.LISTVIEW" _
                OrElse WordsList(1).Word = "MSCOMCTLLIB.LISTVIEW") _
                AndAlso (Not IsActiveXControl) Then
                    NewLinePack.Add(TabSequence(TabCount) & "<ListView")
                    DesignerLinesList.Add(NewLinePack)
                ElseIf (WordsList(1).Word = "COMCTLLIB.TOOLBAR" _
                OrElse WordsList(1).Word = "MSCOMCTLLIB.TOOLBAR") _
                AndAlso (Not IsActiveXControl) Then
                    NewLinePack.Add(TabSequence(TabCount) & "<ToolBar")
                    DesignerLinesList.Add(NewLinePack)
                ElseIf (WordsList(1).Word = "COMCTLLIB.STATUSBAR" _
                OrElse WordsList(1).Word = "MSCOMCTLLIB.STATUSBAR") _
                AndAlso (Not IsActiveXControl) Then
                    NewLinePack.Add(TabSequence(TabCount) & "<StatusBar")
                    DesignerLinesList.Add(NewLinePack)
                ElseIf (WordsList(1).Word = "COMCTLLIB.TREEVIEW" _
                OrElse WordsList(1).Word = "MSCOMCTLLIB.TREEVIEW") _
                AndAlso (Not IsActiveXControl) Then
                    NewLinePack.Add(TabSequence(TabCount) & "<TreeView")
                    DesignerLinesList.Add(NewLinePack)
                ElseIf (WordsList(1).Word.IndexOf(".") > 0) AndAlso (Not WordsList(1).Word.StartsWith("VB.")) AndAlso (Not IsActiveXControl) Then
                    NewLinePack.Add(TabSequence(TabCount) & "<WindowsFormsHost")
                    DesignerLinesList.Add(NewLinePack)
                    k = WordsList(1).Word.IndexOf(".")
                    axNamespace = lin.Substring(WordsList(1).Start, k)
                    ax = lin.Substring(WordsList(1).Start + k + 1, WordsList(1).Word.Length - k - 1)
                    k = ActiveXControlList.IndexOf(axNamespace)
                    If k < 0 Then
                        ActiveXControlList.Add(axNamespace)
                        k = ActiveXControlList.Count - 1
                    End If
                    If k = 0 Then
                        InnerLinePack.Add(TabSequence(TabCount + 1) & "<ax:Ax" & ax)
                    Else
                        InnerLinePack.Add(TabSequence(TabCount + 1) & "<ax" & (k + 1) & ":Ax" & ax)
                    End If
                    DesignerLinesList.Add(InnerLinePack)
                    TabAdjust = TabAdjust + 1
                    IsActiveXControlInUse = True
                    CurrentElementIsActiveXControl = True
                    ElementInfoToUse.Add("EndElementBelow", "1")
                Else
                    NewLinePack.Add(TabSequence(TabCount) & "<!-- " & ReadTextFromLine(lin, WordsList, 1, True, ResourceList, Nothing, "", False) & " {")
                    DesignerLinesList.Add(NewLinePack)
                    ElementInfoToUse.Add("EndElementBelow", "1")
                End If
                If ActiveXControlListToUse Is Nothing Then
                    ActiveXControlListToUse = ActiveXControlList
                End If
                If IsActiveXControlInUse Then
                    LinePackToUse = InnerLinePack
                Else
                    LinePackToUse = NewLinePack
                End If
                j = DesignerLinesList.Count
                i = ReadDesignerElement(i + 1, DesignerLinesList, LinesList, LinePackToUse, ElementInfoToUse, CommentsLinePack, WordsList(1).Word, TabCount + TabAdjust, "", ElementNames, ElementFinalNames, IsActiveXControlInUse, ActiveXControlListToUse, ResourceListToUse, AdditionalResources, ResourceFile, SourcePath, DestinationPath, TopLevelElement, Menu)
                j = AddContentStartInfoToLinePack(ElementInfoToUse, TabCount + TabAdjust, DesignerLinesList, j)
                If WordsList(1).Word = "VB.FORM" Then
                    If Menu.BeginningLine >= 0 Then
                        InnerLinePack = New List(Of String)
                        InnerLinePack.Add(TabSequence(TabCount + 2) & "</Menu>")
                        DesignerLinesList.Insert(Menu.EndingLine, InnerLinePack)
                        l = Menu.EndingLine
                        While l > Menu.BeginningLine
                            l = l - 1
                            DesignerLinesList(l)(0) = vbTab & DesignerLinesList(l)(0)
                        End While
                        InnerLinePack = New List(Of String)
                        InnerLinePack.Add(TabSequence(TabCount + 2) & "<Menu Name=""" & TopLevelElement & "Menu"" VerticalAlignment=""Top"">")
                        DesignerLinesList.Insert(Menu.BeginningLine, InnerLinePack)
                    End If
                    k = AddActiveXNamespacesToLinePack(NewLinePack, ActiveXControlListToUse, k, TabCount + 1)
                    AddResourceNamespacesToLinePack(NewLinePack, ResourceListToUse, k, TabCount + 1)
                    AddTopLevelInfoToLinePack(NewLinePack, ElementInfoToUse, WordsList(1).Word)
                    j = AddResourcesToDesigner(DesignerLinesList, ResourceListToUse, AdditionalResources, ResourceFile, SourcePath, DestinationPath, j - 1, TabCount + 1, ElementInfoToUse, TopLevelElement, WordsList(1).Word) + 1
                    j = AddBackgroundInfoToLinePack(NewLinePack, ElementInfoToUse, DesignerLinesList, j - 1, TabCount + 1, WordsList(1).Word, TopLevelElement) + 1
                    NewLinePack(NewLinePack.Count - 1) = NewLinePack(NewLinePack.Count - 1) & ">"
                ElseIf WordsList(1).Word = "VB.USERCONTROL" _
                OrElse WordsList(1).Word = "VB.USERDOCUMENT" Then
                    k = AddActiveXNamespacesToLinePack(NewLinePack, ActiveXControlListToUse, k, TabCount + 1)
                    AddResourceNamespacesToLinePack(NewLinePack, ResourceListToUse, k, TabCount + 1)
                    AddTopLevelInfoToLinePack(NewLinePack, ElementInfoToUse, WordsList(1).Word)
                    AddMarginInfoToLinePack(NewLinePack, ElementInfoToUse)
                    j = AddResourcesToDesigner(DesignerLinesList, ResourceListToUse, AdditionalResources, ResourceFile, SourcePath, DestinationPath, j - 1, TabCount + 1, ElementInfoToUse, TopLevelElement, WordsList(1).Word) + 1
                    j = AddBackgroundInfoToLinePack(NewLinePack, ElementInfoToUse, DesignerLinesList, j - 1, TabCount + 1, WordsList(1).Word, TopLevelElement) + 1
                    NewLinePack(NewLinePack.Count - 1) = NewLinePack(NewLinePack.Count - 1) & ">"
                ElseIf WordsList(1).Word = "VB.FRAME" AndAlso (Not IsActiveXControl) Then
                    AddNameInfoToLinePack(NewLinePack, ElementNames, ElementFinalNames, ElementInfoToUse)
                    AddMarginInfoToLinePack(NewLinePack, ElementInfoToUse)
                    AddSizeInfoToLinePack(NewLinePack, ElementInfoToUse, WordsList(1).Word)
                    j = AddBackgroundInfoToLinePack(NewLinePack, ElementInfoToUse, DesignerLinesList, j - 1, TabCount + 1, WordsList(1).Word, TopLevelElement) + 1
                    NewLinePack(NewLinePack.Count - 1) = NewLinePack(NewLinePack.Count - 1) & ">"
                ElseIf (WordsList(1).Word = "VB.CHECKBOX" _
                OrElse WordsList(1).Word = "VB.COMMANDBUTTON" _
                OrElse WordsList(1).Word = "VB.LABEL" _
                OrElse WordsList(1).Word = "VB.TEXTBOX" _
                OrElse WordsList(1).Word = "VB.LISTBOX" _
                OrElse WordsList(1).Word = "VB.IMAGE" _
                OrElse WordsList(1).Word = "VB.COMBOBOX" _
                OrElse WordsList(1).Word = "VB.PICTUREBOX" _
                OrElse WordsList(1).Word = "VB.OPTIONBUTTON" _
                OrElse WordsList(1).Word = "VB.MENU" _
                OrElse WordsList(1).Word = "RICHTEXTLIB.RICHTEXTBOX" _
                OrElse WordsList(1).Word = "COMCTLLIB.PROGRESSBAR" _
                OrElse WordsList(1).Word = "MSCOMCTLLIB.PROGRESSBAR" _
                OrElse WordsList(1).Word = "COMCTLLIB.LISTVIEW" _
                OrElse WordsList(1).Word = "MSCOMCTLLIB.LISTVIEW" _
                OrElse WordsList(1).Word = "COMCTLLIB.TOOLBAR" _
                OrElse WordsList(1).Word = "MSCOMCTLLIB.TOOLBAR" _
                OrElse WordsList(1).Word = "COMCTLLIB.STATUSBAR" _
                OrElse WordsList(1).Word = "MSCOMCTLLIB.STATUSBAR" _
                OrElse WordsList(1).Word = "COMCTLLIB.TREEVIEW" _
                OrElse WordsList(1).Word = "MSCOMCTLLIB.TREEVIEW") _
                AndAlso (Not IsActiveXControl) Then
                    AddNameInfoToLinePack(LinePackToUse, ElementNames, ElementFinalNames, ElementInfoToUse)
                    AddMarginInfoToLinePack(LinePackToUse, ElementInfoToUse)
                    AddSizeInfoToLinePack(LinePackToUse, ElementInfoToUse, WordsList(1).Word)
                    AddComboBoxStyleInfoToLinePack(LinePackToUse, ElementInfoToUse, WordsList(1).Word)
                    SwitchIfPasswordBox(LinePackToUse, ElementInfoToUse, WordsList(1).Word)
                    IsContextMenu = SwitchIfContextMenu(LinePackToUse, ElementInfoToUse, WordsList(1).Word, CurrentElementType, CommentsLinePack)
                    j = AddBackgroundInfoToLinePack(LinePackToUse, ElementInfoToUse, DesignerLinesList, j, TabCount + 1, WordsList(1).Word, TopLevelElement)
                    LinePackToUse(LinePackToUse.Count - 1) = LinePackToUse(LinePackToUse.Count - 1) & ">"
                ElseIf CurrentElementIsActiveXControl AndAlso (Not IsActiveXControl) Then
                    ElementInfoToUse.Add("UseXName", "1")
                    AddNameInfoToLinePack(InnerLinePack, ElementNames, ElementFinalNames, ElementInfoToUse)
                    ElementInfoToUse.Remove("UseXName")
                    ElementInfoToUse.Add("IsWindowsFormsHost", "1")
                    AddNameInfoToLinePack(NewLinePack, ElementNames, ElementFinalNames, ElementInfoToUse)
                    ElementInfoToUse.Remove("IsWindowsFormsHost")
                    AddMarginInfoToLinePack(NewLinePack, ElementInfoToUse)
                    AddSizeInfoToLinePack(NewLinePack, ElementInfoToUse, WordsList(1).Word)
                    InnerLinePack(InnerLinePack.Count - 1) = InnerLinePack(InnerLinePack.Count - 1) & ">"
                    NewLinePack(NewLinePack.Count - 1) = NewLinePack(NewLinePack.Count - 1) & ">"
                Else
                    AddNameInfoToLinePack(NewLinePack, ElementNames, ElementFinalNames, ElementInfoToUse)
                    AddMarginInfoToLinePack(NewLinePack, ElementInfoToUse)
                    AddSizeInfoToLinePack(NewLinePack, ElementInfoToUse, WordsList(1).Word)
                    j = AddBackgroundInfoToLinePack(NewLinePack, ElementInfoToUse, DesignerLinesList, j, TabCount + 1, WordsList(1).Word, TopLevelElement)
                    NewLinePack(NewLinePack.Count - 1) = NewLinePack(NewLinePack.Count - 1) & " -->"
                End If
                j = AddContentInfoToLinePack(LinePackToUse, ElementInfoToUse, TabCount + TabAdjust, DesignerLinesList, j, WordsList(1).Word)
                j = AddContentEndInfoToLinePack(ElementInfoToUse, TabCount + TabAdjust, DesignerLinesList, j)
                AddCommentsToDesignerLinesList(CommentsLinePack, DesignerLinesList, j, TabCount + TabAdjust)
                If WordsList(1).Word = "VB.FORM" Then
                    AddElementEnding("Grid", DesignerLinesList, TabCount + 1, ElementInfoToUse)
                    AddElementEnding("Window", DesignerLinesList, TabCount, ElementInfoToUse)
                ElseIf WordsList(1).Word = "VB.USERCONTROL" _
                OrElse WordsList(1).Word = "VB.USERDOCUMENT" Then
                    AddElementEnding("Grid", DesignerLinesList, TabCount + 1, ElementInfoToUse)
                    AddElementEnding("UserControl", DesignerLinesList, TabCount, ElementInfoToUse)
                ElseIf WordsList(1).Word = "VB.FRAME" AndAlso (Not IsActiveXControl) Then
                    AddElementEnding("Grid", DesignerLinesList, TabCount + 1, ElementInfoToUse)
                    AddElementEnding("GroupBox", DesignerLinesList, TabCount, ElementInfoToUse)
                ElseIf WordsList(1).Word = "VB.CHECKBOX" AndAlso (Not IsActiveXControl) Then
                    AddElementEnding("CheckBox", DesignerLinesList, TabCount, ElementInfoToUse)
                ElseIf WordsList(1).Word = "VB.COMMANDBUTTON" AndAlso (Not IsActiveXControl) Then
                    AddElementEnding("Button", DesignerLinesList, TabCount, ElementInfoToUse)
                ElseIf WordsList(1).Word = "VB.LABEL" AndAlso (Not IsActiveXControl) Then
                    AddElementEnding("Label", DesignerLinesList, TabCount, ElementInfoToUse)
                ElseIf WordsList(1).Word = "VB.TEXTBOX" AndAlso (Not IsActiveXControl) Then
                    If ElementInfoToUse.ContainsKey("PasswordChar") Then
                        AddElementEnding("PasswordBox", DesignerLinesList, TabCount, ElementInfoToUse)
                    Else
                        AddElementEnding("TextBox", DesignerLinesList, TabCount, ElementInfoToUse)
                    End If
                ElseIf WordsList(1).Word = "VB.LISTBOX" AndAlso (Not IsActiveXControl) Then
                    AddElementEnding("ListBox", DesignerLinesList, TabCount, ElementInfoToUse)
                ElseIf WordsList(1).Word = "VB.IMAGE" AndAlso (Not IsActiveXControl) Then
                    AddElementEnding("Image", DesignerLinesList, TabCount, ElementInfoToUse)
                ElseIf WordsList(1).Word = "VB.COMBOBOX" AndAlso (Not IsActiveXControl) Then
                    AddElementEnding("ComboBox", DesignerLinesList, TabCount, ElementInfoToUse)
                ElseIf WordsList(1).Word = "VB.PICTUREBOX" AndAlso (Not IsActiveXControl) Then
                    AddElementEnding("Image", DesignerLinesList, TabCount, ElementInfoToUse)
                ElseIf WordsList(1).Word = "VB.OPTIONBUTTON" AndAlso (Not IsActiveXControl) Then
                    AddElementEnding("RadioButton", DesignerLinesList, TabCount, ElementInfoToUse)
                ElseIf WordsList(1).Word = "VB.MENU" AndAlso (Not IsActiveXControl) Then
                    If IsContextMenu Then
                        AddElementEnding("ContextMenu", DesignerLinesList, TabCount, ElementInfoToUse)
                        While DesignerLinesList.Count > MenuLocation
                            AdditionalResources.Add(DesignerLinesList(MenuLocation))
                            DesignerLinesList.RemoveAt(MenuLocation)
                            If Menu IsNot Nothing AndAlso CurrentElementType <> "VB.MENU" AndAlso Menu.EndingLine > MenuLocation Then
                                Menu.EndingLine = Menu.EndingLine - 1
                            End If
                        End While
                    Else
                        AddElementEnding("MenuItem", DesignerLinesList, TabCount, ElementInfoToUse)
                        If Menu IsNot Nothing AndAlso CurrentElementType <> "VB.MENU" Then
                            If Menu.BeginningLine < 0 Then
                                Menu.BeginningLine = MenuLocation
                            End If
                            Menu.EndingLine = DesignerLinesList.Count
                        End If
                    End If
                ElseIf WordsList(1).Word = "RICHTEXTLIB.RICHTEXTBOX" AndAlso (Not IsActiveXControl) Then
                    AddElementEnding("RichTextBox", DesignerLinesList, TabCount, ElementInfoToUse)
                ElseIf (WordsList(1).Word = "COMCTLLIB.PROGRESSBAR" _
                OrElse WordsList(1).Word = "MSCOMCTLLIB.PROGRESSBAR") _
                AndAlso (Not IsActiveXControl) Then
                    AddElementEnding("ProgressBar", DesignerLinesList, TabCount, ElementInfoToUse)
                ElseIf (WordsList(1).Word = "COMCTLLIB.LISTVIEW" _
                OrElse WordsList(1).Word = "MSCOMCTLLIB.LISTVIEW") _
                AndAlso (Not IsActiveXControl) Then
                    AddElementEnding("ListView", DesignerLinesList, TabCount, ElementInfoToUse)
                ElseIf (WordsList(1).Word = "COMCTLLIB.TOOLBAR" _
                OrElse WordsList(1).Word = "MSCOMCTLLIB.TOOLBAR") _
                AndAlso (Not IsActiveXControl) Then
                    AddElementEnding("ToolBar", DesignerLinesList, TabCount, ElementInfoToUse)
                ElseIf (WordsList(1).Word = "COMCTLLIB.STATUSBAR" _
                OrElse WordsList(1).Word = "MSCOMCTLLIB.STATUSBAR") _
                AndAlso (Not IsActiveXControl) Then
                    AddElementEnding("StatusBar", DesignerLinesList, TabCount, ElementInfoToUse)
                ElseIf (WordsList(1).Word = "COMCTLLIB.TREEVIEW" _
                OrElse WordsList(1).Word = "MSCOMCTLLIB.TREEVIEW") _
                AndAlso (Not IsActiveXControl) Then
                    AddElementEnding("TreeView", DesignerLinesList, TabCount, ElementInfoToUse)
                ElseIf CurrentElementIsActiveXControl AndAlso (Not IsActiveXControl) Then
                    If k = 0 Then
                        AddElementEnding("ax:Ax" & ax, DesignerLinesList, TabCount + 1, ElementInfoToUse)
                    Else
                        AddElementEnding("ax" & (k + 1) & ":Ax" & ax, DesignerLinesList, TabCount + 1, ElementInfoToUse)
                    End If
                    AddElementEnding("WindowsFormsHost", DesignerLinesList, TabCount, ElementInfoToUse)
                Else
                    NewLinePack = New List(Of String)
                    NewLinePack.Add(TabSequence(TabCount) & "<!-- } -->")
                    DesignerLinesList.Add(NewLinePack)
                End If
                If CurrentElementType = "" Then
                    Finished = True
                End If
            ElseIf WordsList(0).Word = "BEGINPROPERTY" Then
                NewLinePack = New List(Of String)
                CommentsLinePack = New List(Of String)
                ElementInfoToUse = New Dictionary(Of String, String)
                k = DesignerLinesList.Count
                MenuLocation = -1
                If WordsList(1).Word = "HDRFONT" Then
                    NewLinePack.Add(TabSequence(TabCount) & "<!-- HdrFont { -->")
                    DesignerLinesList.Add(NewLinePack)
                    LinePackToUse = CurrentLinePack
                    PropertyRecognized = True
                ElseIf WordsList(1).Word = "FONT" AndAlso CurrentElementType <> "VB.IMAGE" AndAlso CurrentElementType <> "VB.PICTUREBOX" Then
                    NewLinePack.Add(TabSequence(TabCount) & "<!-- Font { -->")
                    DesignerLinesList.Add(NewLinePack)
                    LinePackToUse = CurrentLinePack
                    PropertyRecognized = True
                ElseIf WordsList(1).Word.StartsWith("BUTTON") AndAlso CurrentElementType = "BUTTONS" Then
                    MenuLocation = DesignerLinesList.Count
                    NewLinePack.Add(TabSequence(TabCount - 1) & "<Button")
                    DesignerLinesList.Add(NewLinePack)
                    LinePackToUse = NewLinePack
                    CopyElement("ImageListName", ElementInfo, ElementInfoToUse)
                    CopyElement("ButtonWidth", ElementInfo, ElementInfoToUse)
                    CopyElement("ButtonHeight", ElementInfo, ElementInfoToUse)
                    CopyElement("TextAlignment", ElementInfo, ElementInfoToUse)
                    ElementInfoToUse.Add("IsToolbarButton", "1")
                    PropertyRecognized = True
                ElseIf WordsList(1).Word.StartsWith("PANEL") AndAlso CurrentElementType = "PANELS" Then
                    MenuLocation = DesignerLinesList.Count
                    NewLinePack.Add(TabSequence(TabCount - 1) & "<StatusBarItem")
                    DesignerLinesList.Add(NewLinePack)
                    LinePackToUse = NewLinePack
                    PropertyRecognized = True
                Else
                    NewLinePack.Add(TabSequence(TabCount) & "<!-- " & ReadTextFromLine(lin, WordsList, 1, True, ResourceList, Nothing, "", False) & " { -->")
                    DesignerLinesList.Add(NewLinePack)
                    NewLinePack.Add(TabSequence(TabCount + 1) & "<!-- ")
                    LinePackToUse = NewLinePack
                    PropertyRecognized = False
                    If WordsList(1).Word = "IMAGES" _
                    AndAlso (CurrentElementType = "COMCTLLIB.IMAGELIST" _
                    OrElse CurrentElementType = "MSCOMCTLLIB.IMAGELIST") Then
                        ElementInfoToUse.Add("ImageListName", ElementInfo("Name"))
                        ElementInfoToUse.Add("ImageListIndex", "0")
                    ElseIf WordsList(1).Word.StartsWith("LISTIMAGE") AndAlso CurrentElementType = "IMAGES" Then
                        CopyElement("ImageListName", ElementInfo, ElementInfoToUse)
                        ElementInfoToUse.Add("ImageListIndex", (Convert.ToInt32(ElementInfo("ImageListIndex")) + 1).ToString)
                        ElementInfo("ImageListIndex") = ElementInfoToUse("ImageListIndex")
                    ElseIf WordsList(1).Word = "BUTTONS" _
                    AndAlso (CurrentElementType = "COMCTLLIB.TOOLBAR" _
                    OrElse CurrentElementType = "MSCOMCTLLIB.TOOLBAR") Then
                        CopyElement("ImageListName", ElementInfo, ElementInfoToUse)
                        CopyElement("ButtonWidth", ElementInfo, ElementInfoToUse)
                        CopyElement("ButtonHeight", ElementInfo, ElementInfoToUse)
                        CopyElement("TextAlignment", ElementInfo, ElementInfoToUse)
                    End If
                End If
                j = DesignerLinesList.Count
                i = ReadDesignerElement(i + 1, DesignerLinesList, LinesList, LinePackToUse, ElementInfoToUse, CommentsLinePack, WordsList(1).Word, TabCount + 1, WordsList(1).Word, ElementNames, ElementFinalNames, IsActiveXControl, ActiveXControlList, ResourceList, AdditionalResources, ResourceFile, SourcePath, DestinationPath, TopLevelElement, Menu)
                j = AddContentStartInfoToLinePack(ElementInfoToUse, TabCount, DesignerLinesList, j)
                If WordsList(1).Word.StartsWith("BUTTON") AndAlso CurrentElementType = "BUTTONS" Then
                    AddButtonSizeInfoToLinePack(NewLinePack, ElementInfoToUse)
                    j = AddToolbarImageInfoToLinePack(ElementInfoToUse, DesignerLinesList, j, TabCount)
                    NewLinePack(NewLinePack.Count - 1) = NewLinePack(NewLinePack.Count - 1) & ">"
                ElseIf WordsList(1).Word.StartsWith("PANEL") AndAlso CurrentElementType = "PANELS" Then
                    NewLinePack(NewLinePack.Count - 1) = NewLinePack(NewLinePack.Count - 1) & ">"
                ElseIf Not PropertyRecognized Then
                    AddLiteralToLinePack(NewLinePack, " -->")
                End If
                j = AddContentInfoToLinePack(LinePackToUse, ElementInfoToUse, TabCount, DesignerLinesList, j, CurrentElementType)
                j = AddContentEndInfoToLinePack(ElementInfoToUse, TabCount, DesignerLinesList, j)
                AddCommentsToDesignerLinesList(CommentsLinePack, DesignerLinesList, j, TabCount + 1)
                If WordsList(1).Word.StartsWith("BUTTON") AndAlso CurrentElementType = "BUTTONS" Then
                    AddElementEnding("Button", DesignerLinesList, TabCount - 1, ElementInfoToUse)
                    If ElementInfoToUse.ContainsKey("Style") Then
                        If Convert.ToInt32(ElementInfoToUse("Style"), Globalization.CultureInfo.InvariantCulture) = 3 Then
                            While DesignerLinesList.Count > MenuLocation
                                DesignerLinesList.RemoveAt(MenuLocation)
                                If Menu IsNot Nothing AndAlso CurrentElementType <> "VB.MENU" AndAlso Menu.EndingLine > MenuLocation Then
                                    Menu.EndingLine = Menu.EndingLine - 1
                                End If
                            End While
                            NewLinePack = New List(Of String)
                            NewLinePack.Add(TabSequence(TabCount - 1) & "<Separator/>")
                            DesignerLinesList.Add(NewLinePack)
                        End If
                    End If
                ElseIf WordsList(1).Word.StartsWith("PANEL") AndAlso CurrentElementType = "PANELS" Then
                    AddElementEnding("StatusBarItem", DesignerLinesList, TabCount - 1, ElementInfoToUse)
                ElseIf PropertyRecognized Then
                    If CommentsLinePack.Count > 0 Then
                        NewLinePack = New List(Of String)
                        NewLinePack.Add(TabSequence(TabCount) & "<!-- } -->")
                        DesignerLinesList.Add(NewLinePack)
                        If Not ElementInfo.ContainsKey("EndElementBelow") Then
                            ElementInfo.Add("EndElementBelow", "1")
                        End If
                    Else
                        DesignerLinesList.RemoveAt(k)
                        If Menu IsNot Nothing AndAlso Menu.EndingLine > k Then
                            Menu.EndingLine = Menu.EndingLine - 1
                        End If
                    End If
                Else
                    NewLinePack = New List(Of String)
                    NewLinePack.Add(TabSequence(TabCount) & "<!-- } -->")
                    DesignerLinesList.Add(NewLinePack)
                    If Not ElementInfo.ContainsKey("EndElementBelow") Then
                        ElementInfo.Add("EndElementBelow", "1")
                    End If
                End If
                If CurrentElementType = "" Then
                    Finished = True
                End If
            ElseIf WordsList(0).Word = "END" AndAlso PropertyName = "" Then
                Finished = True
            ElseIf WordsList(0).Word = "ENDPROPERTY" AndAlso PropertyName <> "" Then
                Finished = True
            ElseIf IsActiveXControl Then
                If WordsList(0).Word.EndsWith("=") Then
                    elm = lin.Substring(WordsList(0).Start, WordsList(0).Word.Length - 1).Trim
                    k = 1
                Else
                    elm = lin.Substring(WordsList(0).Start, WordsList(0).Word.Length).Trim
                    k = 2
                End If
                NewValue = ReadTextFromLine(lin, WordsList, k, False, ResourceList, Nothing, "", False).Trim
                ActiveXCleanup.CleanupProperties(CurrentElementType, PropertyName, elm, NewValue, ResourceList, ElementInfo)
                If NewValue IsNot Nothing Then
                    AddLiteralToLinePack(CurrentLinePack, " ")
                    AddLiteralToLinePack(CurrentLinePack, elm)
                    AddLiteralToLinePack(CurrentLinePack, "=")
                    AddTextToLinePack(CurrentLinePack, NewValue)
                Else
                    For Each lin In LinePack
                        CommentsToAddLinePack.Add(lin.Trim)
                    Next
                End If
            ElseIf WordsList(0).Word = "ALIGNMENT" Then
                Select Case Convert.ToInt32(WordsList(2).Word, Globalization.CultureInfo.InvariantCulture)
                    Case 0
                        AddLiteralToLinePack(CurrentLinePack, " HorizontalContentAlignment=""Left""")
                    Case 1
                        AddLiteralToLinePack(CurrentLinePack, " HorizontalContentAlignment=""Right""")
                    Case 2
                        AddLiteralToLinePack(CurrentLinePack, " HorizontalContentAlignment=""Center""")
                End Select
            ElseIf WordsList(0).Word = "AUTOSIZE" Then
                ElementInfo.Add("AutoSize", ReadTextFromLine(lin, WordsList, 2, False, ResourceList, Nothing, "", False))
            ElseIf WordsList(0).Word = "BACKCOLOR" _
            AndAlso CurrentElementType <> "VB.IMAGE" _
            AndAlso CurrentElementType <> "VB.PICTUREBOX" Then
                ElementInfo.Add("Background", ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False))
            ElseIf WordsList(0).Word = "BACKSTYLE" Then
                ElementInfo.Add("Opacity", ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False))
            ElseIf WordsList(0).Word = "BORDERSTYLE" Then
                ElementInfo.Add("BorderStyle", ReadTextFromLine(lin, WordsList, 2, False, ResourceList, Nothing, "", False))
            ElseIf WordsList(0).Word = "BUTTONHEIGHT" Then
                'ElementInfo.Add("ButtonHeight", ReadTextFromLine(lin, WordsList, 2, False, ResourceList, Nothing, "", False))
            ElseIf WordsList(0).Word = "BUTTONWIDTH" Then
                'ElementInfo.Add("ButtonWidth", ReadTextFromLine(lin, WordsList, 2, False, ResourceList, Nothing, "", False))
            ElseIf WordsList(0).Word = "CAPTION" Then
                If CurrentElementType = "VB.FORM" _
                OrElse CurrentElementType = "VB.USERCONTROL" _
                OrElse CurrentElementType = "VB.USERDOCUMENT" Then
                    AddLiteralToLinePack(CurrentLinePack, " Title=")
                    AddTextToLinePack(CurrentLinePack, ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False))
                ElseIf CurrentElementType = "VB.FRAME" Then
                    AddLiteralToLinePack(CurrentLinePack, " Header=")
                    AddTextToLinePack(CurrentLinePack, ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False))
                ElseIf CurrentElementType = "VB.MENU" Then
                    ElementInfo.Add("MenuHeader", ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False))
                Else
                    ElementInfo.Add("Content", ReadTextFromLine(lin, WordsList, 2, True, ResourceList, ElementInfo, "ContentLocation", False))
                    IncrementContentCount(ElementInfo)
                    If CurrentElementType.StartsWith("BUTTON") Then
                        If ElementInfo.ContainsKey("TextAlignment") AndAlso Convert.ToInt32(ElementInfo("TextAlignment"), Globalization.CultureInfo.InvariantCulture) = 1 Then
                            ElementInfo.Add("ContentVerticalAlignment", "Center")
                        Else
                            ElementInfo.Add("ContentHorizontalAlignment", "Center")
                        End If
                    End If
                End If
            ElseIf WordsList(0).Word = "CHECKED" AndAlso CurrentElementType = "VB.MENU" Then
                AddLiteralToLinePack(CurrentLinePack, " IsCheckable=""True"" IsChecked=")
                If Convert.ToInt32(WordsList(2).Word, Globalization.CultureInfo.InvariantCulture) = 0 Then
                    AddTextToLinePack(CurrentLinePack, "False")
                Else
                    AddTextToLinePack(CurrentLinePack, "True")
                End If
            ElseIf WordsList(0).Word = "CLIENTHEIGHT" Then
                AddLiteralToLinePack(CurrentLinePack, " Height=""")
                AddScreenCoordToLinePack(CurrentLinePack, ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False), 38)
                AddLiteralToLinePack(CurrentLinePack, """")
            ElseIf WordsList(0).Word = "CLIENTLEFT" Then
                If CurrentElementType = "VB.FORM" Then
                    AddLiteralToLinePack(CurrentLinePack, " Left=""")
                    AddScreenCoordToLinePack(CurrentLinePack, ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False), 0)
                    AddLiteralToLinePack(CurrentLinePack, """")
                Else
                    ElementInfo.Add("Left", ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False))
                End If
            ElseIf WordsList(0).Word = "CLIENTTOP" Then
                If CurrentElementType = "VB.FORM" Then
                    AddLiteralToLinePack(CurrentLinePack, " Top=""")
                    AddScreenCoordToLinePack(CurrentLinePack, ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False), 0)
                    AddLiteralToLinePack(CurrentLinePack, """")
                Else
                    ElementInfo.Add("Top", ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False))
                End If
            ElseIf WordsList(0).Word = "CLIENTWIDTH" Then
                AddLiteralToLinePack(CurrentLinePack, " Width=""")
                AddScreenCoordToLinePack(CurrentLinePack, ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False), 22)
                AddLiteralToLinePack(CurrentLinePack, """")
            ElseIf WordsList(0).Word = "ENABLED" Then
                If Convert.ToInt32(WordsList(2).Word, Globalization.CultureInfo.InvariantCulture) = 0 Then
                    AddLiteralToLinePack(CurrentLinePack, " IsEnabled=""False""")
                End If
            ElseIf WordsList(0).Word = "FORECOLOR" _
            AndAlso CurrentElementType <> "VB.IMAGE" _
            AndAlso CurrentElementType <> "VB.PICTUREBOX" Then
                AddLiteralToLinePack(CurrentLinePack, " Foreground=""")
                AddLiteralToLinePack(CurrentLinePack, ConvertColor(ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False)))
                AddLiteralToLinePack(CurrentLinePack, """")
            ElseIf WordsList(0).Word = "HEIGHT" Then
                ElementInfo.Add("Height", ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False))
            ElseIf WordsList(0).Word = "ICON" Then
                If WordsList(2).Word.Trim.Replace("""", "") <> "" Then
                    lin = ReadTextFromLine(lin, WordsList, 2, False, ResourceList, Nothing, "", False)
                    ResourceFilename = lin.Substring(0, lin.LastIndexOf(":") - 1).Trim.Replace("""", "")
                    ResourceFilename = IO.Path.GetFileNameWithoutExtension(ResourceFilename)
                    ResourceLocation = lin.Substring(lin.LastIndexOf(":") + 1)
                    AddLiteralToLinePack(CurrentLinePack, " Icon=""")
                    If CurrentElementType = "VB.FORM" _
                    OrElse CurrentElementType = "VB.USERCONTROL" _
                    OrElse CurrentElementType = "VB.USERDOCUMENT" Then
                        AddLiteralToLinePack(CurrentLinePack, "{DynamicResource " & ResourceFilename & "ResourceAt" & ResourceLocation & "}")
                    Else
                        AddLiteralToLinePack(CurrentLinePack, "{StaticResource " & ResourceFilename & "ResourceAt" & ResourceLocation & "}")
                    End If
                    AddLiteralToLinePack(CurrentLinePack, """")
                    res = New ResourceData
                    res.Type = "Image"
                    res.ElementInfo = ElementInfo
                    ResourceList.Add(ResourceLocation, res)
                End If
            ElseIf WordsList(0).Word = "IMAGEINDEX" Then
                ElementInfo.Add("ToolbarImage", ElementInfo("ImageListName").Replace("""", "") & "_" & ReadTextFromLine(lin, WordsList, 2, False, ResourceList, Nothing, "", False))
                IncrementContentCount(ElementInfo)
            ElseIf WordsList(0).Word = "INDEX" Then
                ElementInfo.Add("Index", ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False))
                ElementNames(ElementInfo("Name")) = ElementNames(ElementInfo("Name")).Replace("*", ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False))
            ElseIf WordsList(0).Word = "ITALIC" AndAlso PropertyName = "FONT" Then
                If Convert.ToInt32(WordsList(2).Word, Globalization.CultureInfo.InvariantCulture) <> 0 Then
                    AddLiteralToLinePack(CurrentLinePack, " FontStyle=""Italic""")
                End If
            ElseIf WordsList(0).Word = "LEFT" Then
                If CurrentElementType = "VB.FORM" Then
                    AddLiteralToLinePack(CurrentLinePack, " Left=""")
                    AddScreenCoordToLinePack(CurrentLinePack, ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False), 0)
                    AddLiteralToLinePack(CurrentLinePack, """")
                Else
                    ElementInfo.Add("Left", ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False))
                End If
            ElseIf WordsList(0).Word = "LOCKED" Then
                If Convert.ToInt32(WordsList(2).Word, Globalization.CultureInfo.InvariantCulture) <> 0 Then
                    AddLiteralToLinePack(CurrentLinePack, " IsReadOnly=""True""")
                End If
            ElseIf WordsList(0).Word = "MAXBUTTON" Then
                ElementInfo.Add("MaxButton", ReadTextFromLine(lin, WordsList, 2, False, ResourceList, Nothing, "", False))
            ElseIf WordsList(0).Word = "MAXLENGTH" Then
                AddLiteralToLinePack(CurrentLinePack, " MaxLength=""")
                AddLiteralToLinePack(CurrentLinePack, ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False))
                AddLiteralToLinePack(CurrentLinePack, """")
            ElseIf WordsList(0).Word = "MINBUTTON" Then
                ElementInfo.Add("MinButton", ReadTextFromLine(lin, WordsList, 2, False, ResourceList, Nothing, "", False))
            ElseIf WordsList(0).Word = "MULTILINE" Then
                If Convert.ToString(WordsList(2).Word, Globalization.CultureInfo.InvariantCulture) <> 0 Then
                    AddLiteralToLinePack(CurrentLinePack, " TextWrapping=""Wrap""")
                End If
            ElseIf WordsList(0).Word = "NAME" AndAlso PropertyName = "FONT" Then
                AddLiteralToLinePack(CurrentLinePack, " FontFamily=")
                AddLiteralToLinePack(CurrentLinePack, ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False))
            ElseIf WordsList(0).Word = "PASSWORDCHAR" Then
                ElementInfo.Add("PasswordChar", ReadTextFromLine(lin, WordsList, 2, False, ResourceList, Nothing, "", False))
            ElseIf WordsList(0).Word = "PICTURE" Then
                If WordsList(2).Word.Trim.Replace("""", "") <> "" Then
                    If CurrentElementType = "VB.IMAGE" _
                    OrElse CurrentElementType = "VB.PICTUREBOX" Then
                        lin = ReadTextFromLine(lin, WordsList, 2, False, ResourceList, Nothing, "", False)
                        ResourceFilename = lin.Substring(0, lin.LastIndexOf(":") - 1).Trim.Replace("""", "")
                        ResourceFilename = IO.Path.GetFileNameWithoutExtension(ResourceFilename)
                        ResourceLocation = lin.Substring(lin.LastIndexOf(":") + 1)
                        AddLiteralToLinePack(CurrentLinePack, " Source=""")
                        AddLiteralToLinePack(CurrentLinePack, "{StaticResource " & ResourceFilename & "ResourceAt" & ResourceLocation & "}")
                        AddLiteralToLinePack(CurrentLinePack, """")
                        res = New ResourceData
                        res.Type = "Image"
                        res.ElementInfo = ElementInfo
                        ResourceList.Add(ResourceLocation, res)
                    Else
                        ElementInfo.Add("BackgroundImage", ReadTextFromLine(lin, WordsList, 2, False, ResourceList, Nothing, "", False))
                        res = New ResourceData
                        res.Type = "Image"
                        res.ElementInfo = ElementInfo
                        ResourceList.Add(WordsList(2).Word.Substring(WordsList(2).Word.LastIndexOf(":") + 1), res)
                        IncrementContentCount(ElementInfo)
                    End If
                End If
            ElseIf WordsList(0).Word = "SCALEHEIGHT" Then
                ElementInfo.Add("ScaleHeight", ReadTextFromLine(lin, WordsList, 2, False, ResourceList, Nothing, "", False))
            ElseIf WordsList(0).Word = "SCALEWIDTH" Then
                ElementInfo.Add("ScaleWidth", ReadTextFromLine(lin, WordsList, 2, False, ResourceList, Nothing, "", False))
            ElseIf WordsList(0).Word = "SHOWINTASKBAR" Then
                If Convert.ToString(WordsList(2).Word, Globalization.CultureInfo.InvariantCulture) = 0 Then
                    AddLiteralToLinePack(CurrentLinePack, " ShowInTaskbar=""False""")
                End If
            ElseIf WordsList(0).Word = "STARTUPPOSITION" Then
                Select Case Convert.ToInt32(WordsList(2).Word, Globalization.CultureInfo.InvariantCulture)
                    Case 0
                        AddLiteralToLinePack(CurrentLinePack, " WindowStartupLocation=""Manual""")
                    Case 1
                        AddLiteralToLinePack(CurrentLinePack, " WindowStartupLocation=""CenterOwner""")
                    Case 2
                        AddLiteralToLinePack(CurrentLinePack, " WindowStartupLocation=""CenterScreen""")
                End Select
            ElseIf WordsList(0).Word = "STYLE" _
            AndAlso CurrentElementType = "VB.COMBOBOX" Then
                ElementInfo.Add("Style", WordsList(2).Word)
            ElseIf WordsList(0).Word = "STYLE" _
            AndAlso CurrentElementType.StartsWith("BUTTON") _
            AndAlso CurrentElementType.Length > 6 Then
                ElementInfo.Add("Style", WordsList(2).Word)
            ElseIf WordsList(0).Word = "SIZE" AndAlso PropertyName = "FONT" Then
                AddLiteralToLinePack(CurrentLinePack, " FontSize=""")
                AddLiteralToLinePack(CurrentLinePack, ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False))
                AddLiteralToLinePack(CurrentLinePack, "pt""")
            ElseIf WordsList(0).Word = "STRIKETHROUGH" AndAlso PropertyName = "FONT" Then
                If Convert.ToInt32(WordsList(2).Word, Globalization.CultureInfo.InvariantCulture) <> 0 Then
                    ElementInfo.Add("Strikethrough", "1")
                End If
            ElseIf WordsList(0).Word = "STRETCH" Then
                If Convert.ToInt32(WordsList(2).Word, Globalization.CultureInfo.InvariantCulture) <> 0 Then
                    AddLiteralToLinePack(CurrentLinePack, " Stretch=""Fill""")
                End If
            ElseIf WordsList(0).Word = "TABINDEX" _
            AndAlso CurrentElementType <> "VB.IMAGE" _
            AndAlso CurrentElementType <> "VB.PICTUREBOX" Then
                AddLiteralToLinePack(CurrentLinePack, " TabIndex=""")
                AddLiteralToLinePack(CurrentLinePack, ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False))
                AddLiteralToLinePack(CurrentLinePack, """")
            ElseIf WordsList(0).Word = "TABSTOP" Then
                If Convert.ToInt32(WordsList(2).Word, Globalization.CultureInfo.InvariantCulture) = 0 Then
                    AddLiteralToLinePack(CurrentLinePack, " IsTabStop=""False""")
                End If
            ElseIf WordsList(0).Word = "TEXT" Then
                If CurrentElementType.StartsWith("PANEL") Then
                    If CurrentContentCount(ElementInfo) = 0 Then
                        ElementInfo.Add("Content", ReadTextFromLine(lin, WordsList, 2, True, ResourceList, ElementInfo, "ContentLocation", False))
                        IncrementContentCount(ElementInfo)
                    End If
                Else
                    AddLiteralToLinePack(CurrentLinePack, " Text=")
                    AddTextToLinePack(CurrentLinePack, ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", True))
                End If
            ElseIf WordsList(0).Word = "TEXTSAVE" AndAlso CurrentElementType.StartsWith("PANEL") Then
                If CurrentContentCount(ElementInfo) = 0 Then
                    ElementInfo.Add("Content", ReadTextFromLine(lin, WordsList, 2, True, ResourceList, ElementInfo, "ContentLocation", False))
                    IncrementContentCount(ElementInfo)
                End If
            ElseIf WordsList(0).Word = "TOOLTIPTEXT" _
            OrElse WordsList(0).Word = "OBJECT.TOOLTIPTEXT" Then
                AddLiteralToLinePack(CurrentLinePack, " ToolTip=")
                AddTextToLinePack(CurrentLinePack, ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False))
            ElseIf WordsList(0).Word = "TOP" Then
                If CurrentElementType = "VB.FORM" Then
                    AddLiteralToLinePack(CurrentLinePack, " Top=""")
                    AddScreenCoordToLinePack(CurrentLinePack, ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False), 0)
                    AddLiteralToLinePack(CurrentLinePack, """")
                Else
                    ElementInfo.Add("Top", ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False))
                End If
            ElseIf WordsList(0).Word = "UNDERLINE" AndAlso PropertyName = "FONT" Then
                If Convert.ToInt32(WordsList(2).Word, Globalization.CultureInfo.InvariantCulture) <> 0 Then
                    ElementInfo.Add("Underline", "1")
                End If
            ElseIf WordsList(0).Word = "VISIBLE" _
            OrElse WordsList(0).Word = "OBJECT.VISIBLE" Then
                If CurrentElementType = "VB.MENU" Then
                    If Convert.ToInt32(WordsList(2).Word, Globalization.CultureInfo.InvariantCulture) = 0 Then
                        ElementInfo.Add("Visible", "0")
                    End If
                Else
                    AddLiteralToLinePack(CurrentLinePack, " Visibility=")
                    If Convert.ToInt32(WordsList(2).Word, Globalization.CultureInfo.InvariantCulture) = 0 Then
                        AddTextToLinePack(CurrentLinePack, "Collapsed")
                    Else
                        AddTextToLinePack(CurrentLinePack, "Visible")
                    End If
                End If
            ElseIf WordsList(0).Word = "WEIGHT" AndAlso PropertyName = "FONT" Then
                If Convert.ToInt32(WordsList(2).Word, Globalization.CultureInfo.InvariantCulture) > 0 Then
                    AddLiteralToLinePack(CurrentLinePack, " FontWeight=""Bold""")
                End If
            ElseIf WordsList(0).Word = "WIDTH" Then
                ElementInfo.Add("Width", ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False))
            ElseIf WordsList(0).Word = "WINDOWSTATE" Then
                Select Case Convert.ToInt32(WordsList(2).Word, Globalization.CultureInfo.InvariantCulture)
                    Case 1
                        AddLiteralToLinePack(CurrentLinePack, " WindowState=""Minimized""")
                    Case 2
                        AddLiteralToLinePack(CurrentLinePack, " WindowState=""Maximized""")
                End Select
            Else
                For Each lin In LinePack
                    CommentsToAddLinePack.Add(lin.Trim)
                Next
                If (ElementInfo IsNot Nothing) AndAlso (Not ElementInfo.ContainsKey("EndElementBelow")) Then
                    ElementInfo.Add("EndElementBelow", "1")
                End If
                If WordsList(0).Word = "IMAGELIST" Then
                    ElementInfo.Add("ImageListName", ReadTextFromLine(lin, WordsList, 2, True, ResourceList, Nothing, "", False))
                End If
                If WordsList(0).Word = "TEXTALIGNMENT" Then
                    ElementInfo.Add("TextAlignment", ReadTextFromLine(lin, WordsList, 2, False, ResourceList, Nothing, "", False))
                End If
            End If
            If Not Finished Then
                i = i + 1
            End If
        End While
        Return i

    End Function

    Private Function BuildDesignerLinesList(ByVal i As Integer, ByVal DesignerLinesList As List(Of List(Of String)), ByVal LinesList As List(Of List(Of String)), ByVal ElementNames As Dictionary(Of String, String), ByVal ElementFinalNames As Dictionary(Of String, String), ByVal ResourceFile As String, ByVal SourcePath As String, ByVal DestinationPath As String, ByVal TopLevelElement As String) As Integer

        Dim CommentsLinePack As List(Of String)

        CommentsLinePack = New List(Of String)
        i = ReadDesignerElement(i, DesignerLinesList, LinesList, Nothing, Nothing, CommentsLinePack, "", 0, "", ElementNames, ElementFinalNames, False, Nothing, Nothing, Nothing, ResourceFile, SourcePath, DestinationPath, TopLevelElement, Nothing)
        AddCommentsToDesignerLinesList(CommentsLinePack, DesignerLinesList, 0, 0)
        Return i + 1

    End Function

    Private Function CleanupAndAddLines(ByVal LinesList As List(Of List(Of String)), ByVal i As Integer, ByVal FinalLinesList As List(Of List(Of String)), ByVal ElementNames As Dictionary(Of String, String), ByVal ElementFinalNames As Dictionary(Of String, String), ByVal SourceType As String)

        Dim lin As String
        Dim LinePack As List(Of String)
        Dim FinalLinePack As List(Of String)
        Dim WordsList As List(Of WordData)
        Dim WordInUse As WordData
        Dim ElementNameItem As KeyValuePair(Of String, String)
        Dim j As Integer
        Dim EventName As String

        lin = ""
        While i < LinesList.Count
            LinePack = LinesList(i)
            WordsList = WordsInLinePack(LinePack)
            WordInUse = StartingWord(WordsList, "SET")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = 0 Then
                WordsList = EraseWord(WordInUse, LinePack)
            End If
            WordInUse = StartingWord(WordsList, "LET")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = 0 Then
                WordsList = EraseWord(WordInUse, LinePack)
            End If
            WordInUse = StartingWord(WordsList, "WEND")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = 0 Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "End While")
            End If
            WordInUse = StartingWord(WordsList, "AS", "VARIANT")
            If WordInUse IsNot Nothing Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "As", "Object")
            End If
            WordInUse = StartingWord(WordsList, "AS", "VARIANT)")
            If WordInUse IsNot Nothing Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "As", "Object)")
            End If
            WordInUse = StartingWord(WordsList, "AS", "VARIANT,")
            If WordInUse IsNot Nothing Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "As", "Object,")
            End If
            WordInUse = StartingWord(WordsList, "AS", "ANY")
            If WordInUse IsNot Nothing Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "As", "Object")
            End If
            WordInUse = StartingWord(WordsList, "AS", "ANY)")
            If WordInUse IsNot Nothing Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "As", "Object)")
            End If
            WordInUse = StartingWord(WordsList, "AS", "ANY,")
            If WordInUse IsNot Nothing Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "As", "Object,")
            End If
            WordInUse = StartingWord(WordsList, "=", "NULL")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = WordsList.Count - 2 Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "=", "Nothing")
            End If
            WordInUse = StartingWord(WordsList, "=NULL")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = WordsList.Count - 1 Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "=Nothing")
            End If
            WordInUse = StartingWord(WordsList, "=", "EMPTY")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = WordsList.Count - 2 Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "=", "Nothing")
            End If
            WordInUse = StartingWord(WordsList, "=EMPTY")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = WordsList.Count - 1 Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "=Nothing")
            End If
            WordInUse = StartingWord(WordsList, "DIM", "ERROR")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = 0 Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "Dim", "[Error]")
            End If
            WordInUse = StartingWord(WordsList, "PUBLIC", "ERROR")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = 0 Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "Public", "[Error]")
            End If
            WordInUse = StartingWord(WordsList, "PRIVATE", "ERROR")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = 0 Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "Private", "[Error]")
            End If
            WordInUse = StartingWord(WordsList, "ERROR", "=")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = 0 Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "[Error]", "=")
            End If
            WordInUse = StartingWord(WordsList, "IF", "ERROR")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = 0 Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "If", "[Error]")
            End If
            WordInUse = StartingWord(WordsList, "DIM", "INTERFACE")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = 0 Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "Dim", "[Interface]")
            End If
            WordInUse = StartingWord(WordsList, "PUBLIC", "INTERFACE")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = 0 Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "Public", "[Interface]")
            End If
            WordInUse = StartingWord(WordsList, "PRIVATE", "INTERFACE")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = 0 Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "Private", "[Interface]")
            End If
            WordInUse = StartingWord(WordsList, "INTERFACE", "=")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = 0 Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "[Interface]", "=")
            End If
            WordInUse = StartingWord(WordsList, "IF", "INTERFACE")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = 0 Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "If", "[Interface]")
            End If
            WordInUse = StartingWord(WordsList, "DIM", "CONTINUE")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = 0 Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "Dim", "[Continue]")
            End If
            WordInUse = StartingWord(WordsList, "PUBLIC", "CONTINUE")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = 0 Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "Public", "[Continue]")
            End If
            WordInUse = StartingWord(WordsList, "PRIVATE", "CONTINUE")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = 0 Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "Private", "[Continue]")
            End If
            WordInUse = StartingWord(WordsList, "CONTINUE", "=")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = 0 Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "[Continue]", "=")
            End If
            WordInUse = StartingWord(WordsList, "IF", "CONTINUE")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = 0 Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "If", "[Continue]")
            End If
            WordInUse = StartingWord(WordsList, "PUBLIC", "TYPE")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = 0 Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "Public", "Structure")
            End If
            WordInUse = StartingWord(WordsList, "PRIVATE", "TYPE")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = 0 Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "Private", "Structure")
            End If
            WordInUse = StartingWord(WordsList, "END", "TYPE")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index = 0 Then
                WordsList = ReplaceWords(WordInUse, WordsList, LinePack, "End", "Structure")
            End If
            WordInUse = StartingWord(WordsList, "SUB")
            If WordInUse IsNot Nothing AndAlso WordInUse.Index < WordsList.Count - 1 Then
                WordInUse = WordsList(WordInUse.Index + 1)
                j = WordInUse.Word.IndexOf("(")
                lin = ""
                If j > 0 Then
                    lin = LinePack(WordInUse.Line).Substring(WordInUse.Start, j)
                ElseIf j < 0 Then
                    If WordInUse.Index = WordsList.Count - 1 _
                    OrElse WordsList(WordInUse.Index + 1).Word.StartsWith("(") Then
                        lin = LinePack(WordInUse.Line).Substring(WordInUse.Start + WordInUse.Word.Length).Trim
                    End If
                End If
                If lin <> "" Then
                    For Each ElementNameItem In ElementNames
                        If ElementFinalNames.ContainsKey(ElementNameItem.Key) Then
                            j = (ElementNameItem.Key.ToUpper & "_").Length
                            If lin.ToUpper.StartsWith(ElementNameItem.Key.ToUpper & "_") _
                            AndAlso lin.ToUpper.Length > j Then
                                EventName = lin.Substring(j)
                                AddLiteralToLinePack(LinePack, " Handles " & ElementFinalNames(ElementNameItem.Key))
                                If ElementNameItem.Value <> "*" Then
                                    AddLiteralToLinePack(LinePack, ElementNameItem.Value.Replace(",", "." & EventName & ", " & ElementFinalNames(ElementNameItem.Key)))
                                End If
                                AddLiteralToLinePack(LinePack, "." & EventName)
                                Exit For
                            End If
                        End If
                    Next
                    j = (SourceType.ToUpper & "_").Length
                    If lin.ToUpper.StartsWith(SourceType.ToUpper & "_") _
                    AndAlso lin.ToUpper.Length > j Then
                        If lin.ToUpper.EndsWith("_INITIALIZE") Then
                            j = WordInUse.Word.IndexOf("(")
                            If j > 0 Then
                                LinePack(WordInUse.Line) = LinePack(WordInUse.Line).Substring(0, WordInUse.Start) & "New" & LinePack(WordInUse.Line).Substring(WordInUse.Start + j)
                            Else
                                LinePack(WordInUse.Line) = LinePack(WordInUse.Line).Substring(0, WordInUse.Start) & "New" & LinePack(WordInUse.Line).Substring(WordInUse.Start + WordInUse.Word.Length)
                            End If
                        ElseIf lin.ToUpper.EndsWith("_TERMINATE") Then
                            j = WordInUse.Word.IndexOf("(")
                            If j > 0 Then
                                LinePack(WordInUse.Line) = LinePack(WordInUse.Line).Substring(0, WordInUse.Start) & "Dispose" & LinePack(WordInUse.Line).Substring(WordInUse.Start + j)
                            Else
                                LinePack(WordInUse.Line) = LinePack(WordInUse.Line).Substring(0, WordInUse.Start) & "Dispose" & LinePack(WordInUse.Line).Substring(WordInUse.Start + WordInUse.Word.Length)
                            End If
                        Else
                            EventName = lin.Substring(j)
                            AddLiteralToLinePack(LinePack, " Handles Me." & EventName)
                        End If
                    End If
                End If
            End If
            FinalLinePack = New List(Of String)
            For Each lin In LinePack
                If lin.Trim <> "" Then
                    lin = vbTab & lin
                End If
                FinalLinePack.Add(lin)
            Next
            FinalLinesList.Add(FinalLinePack)
            i = i + 1
        End While
        Return lin

    End Function

    Private Sub CreateForm(ByVal SourceFile As String, ByVal SourcePath As String, ByVal DestinationPath As String, ByVal DoNotOverwriteVbSources As Boolean)

        Dim LinesList As List(Of List(Of String))
        Dim FinalLinesList As List(Of List(Of String))
        Dim AttributesList As List(Of String)
        Dim DesignerLinesList As List(Of List(Of String))
        Dim ElementNames As Dictionary(Of String, String)
        Dim ElementFinalNames As Dictionary(Of String, String)
        Dim FilenameToUse As String
        Dim m As Integer
        Dim i As Integer
        Dim LinePack As List(Of String)
        Dim AttributeFound As Boolean
        Dim lin As String
        Dim linUpper As String
        Dim linUpperTrim As String
        Dim FinalLinePack As List(Of String)
        Dim ModuleName As String
        Dim ResourceFile As String

        LinesList = LoadSourceFile(SourceFile)
        FinalLinesList = New List(Of List(Of String))
        AttributesList = New List(Of String)
        DesignerLinesList = New List(Of List(Of String))
        ElementNames = New Dictionary(Of String, String)
        ElementFinalNames = New Dictionary(Of String, String)
        FilenameToUse = ""
        m = LinesList.Count
        i = 0
        If m > 0 Then
            LinePack = LinesList(i)
            If LinePack.Count = 1 Then
                lin = LinePack(0)
                linUpper = lin.ToUpper
                linUpperTrim = linUpper.Trim
                If linUpperTrim.StartsWith("VERSION") Then
                    ResourceFile = SourceFile.Substring(0, SourceFile.Length - 4) & ".frx"
                    i = BuildDesignerLinesList(i + 1, DesignerLinesList, LinesList, ElementNames, ElementFinalNames, ResourceFile, SourcePath, DestinationPath, "Window")
                End If
            End If
            Do
                AttributeFound = False
                LinePack = LinesList(i)
                If LinePack.Count = 1 Then
                    lin = LinePack(0)
                    linUpper = lin.ToUpper
                    linUpperTrim = linUpper.Trim
                    If linUpperTrim.StartsWith("ATTRIBUTE ") Then
                        If linUpperTrim.Contains("VB_NAME") Then
                            FilenameToUse = lin.Substring(linUpper.IndexOf("=") + 1).Trim.Replace("""", "")
                        Else
                            AttributesList.Add("' " & lin.Substring(linUpper.IndexOf("ATTRIBUTE ") + 10))
                        End If
                        AttributeFound = True
                    End If
                End If
                i = i + 1
            Loop While AttributeFound AndAlso i < LinesList.Count
            For Each lin In AttributesList
                LinePack = New List(Of String)
                LinePack.Add(lin)
                FinalLinesList.Add(LinePack)
            Next
        End If
        If FilenameToUse = "" Then
            ModuleName = IO.Path.GetFileNameWithoutExtension(SourceFile)
        Else
            ModuleName = FilenameToUse
        End If
        FinalLinePack = New List(Of String)
        FinalLinePack.Add("Public Class " & ModuleName)
        FinalLinesList.Add(FinalLinePack)
        FinalLinePack = New List(Of String)
        FinalLinePack.Add("")
        FinalLinesList.Add(FinalLinePack)
        lin = CleanupAndAddLines(LinesList, i, FinalLinesList, ElementNames, ElementFinalNames, "Form")
        If lin.Trim <> "" Then
            FinalLinePack = New List(Of String)
            FinalLinePack.Add("")
            FinalLinesList.Add(FinalLinePack)
        End If
        FinalLinePack = New List(Of String)
        FinalLinePack.Add("End Class")
        FinalLinesList.Add(FinalLinePack)
        SaveDestinationFile(DesignerLinesList, ModuleName & ".xaml", SourceFile, SourcePath, DestinationPath, False)
        SaveDestinationFile(FinalLinesList, ModuleName & ".xaml.vb", SourceFile, SourcePath, DestinationPath, DoNotOverwriteVbSources)

    End Sub

    Private Sub CreateUserControl(ByVal SourceFile As String, ByVal SourcePath As String, ByVal DestinationPath As String, ByVal DoNotOverwriteVbSources As Boolean)

        Dim LinesList As List(Of List(Of String))
        Dim FinalLinesList As List(Of List(Of String))
        Dim AttributesList As List(Of String)
        Dim DesignerLinesList As List(Of List(Of String))
        Dim ElementNames As Dictionary(Of String, String)
        Dim ElementFinalNames As Dictionary(Of String, String)
        Dim FilenameToUse As String
        Dim m As Integer
        Dim i As Integer
        Dim LinePack As List(Of String)
        Dim AttributeFound As Boolean
        Dim lin As String
        Dim linUpper As String
        Dim linUpperTrim As String
        Dim FinalLinePack As List(Of String)
        Dim ModuleName As String
        Dim ResourceFile As String

        LinesList = LoadSourceFile(SourceFile)
        FinalLinesList = New List(Of List(Of String))
        AttributesList = New List(Of String)
        DesignerLinesList = New List(Of List(Of String))
        ElementNames = New Dictionary(Of String, String)
        ElementFinalNames = New Dictionary(Of String, String)
        FilenameToUse = ""
        m = LinesList.Count
        i = 0
        If m > 0 Then
            LinePack = LinesList(i)
            If LinePack.Count = 1 Then
                lin = LinePack(0)
                linUpper = lin.ToUpper
                linUpperTrim = linUpper.Trim
                If linUpperTrim.StartsWith("VERSION") Then
                    ResourceFile = SourceFile.Substring(0, SourceFile.Length - 4) & ".ctx"
                    i = BuildDesignerLinesList(i + 1, DesignerLinesList, LinesList, ElementNames, ElementFinalNames, ResourceFile, SourcePath, DestinationPath, "UserControl")
                End If
            End If
            Do
                AttributeFound = False
                LinePack = LinesList(i)
                If LinePack.Count = 1 Then
                    lin = LinePack(0)
                    linUpper = lin.ToUpper
                    linUpperTrim = linUpper.Trim
                    If linUpperTrim.StartsWith("ATTRIBUTE ") Then
                        If linUpperTrim.Contains("VB_NAME") Then
                            FilenameToUse = lin.Substring(linUpper.IndexOf("=") + 1).Trim.Replace("""", "")
                        Else
                            AttributesList.Add("' " & lin.Substring(linUpper.IndexOf("ATTRIBUTE ") + 10))
                        End If
                        AttributeFound = True
                    End If
                End If
                i = i + 1
            Loop While AttributeFound AndAlso i < LinesList.Count
            For Each lin In AttributesList
                LinePack = New List(Of String)
                LinePack.Add(lin)
                FinalLinesList.Add(LinePack)
            Next
        End If
        If FilenameToUse = "" Then
            ModuleName = IO.Path.GetFileNameWithoutExtension(SourceFile)
        Else
            ModuleName = FilenameToUse
        End If
        FinalLinePack = New List(Of String)
        FinalLinePack.Add("Public Class " & ModuleName)
        FinalLinesList.Add(FinalLinePack)
        FinalLinePack = New List(Of String)
        FinalLinePack.Add("")
        FinalLinesList.Add(FinalLinePack)
        lin = CleanupAndAddLines(LinesList, i, FinalLinesList, ElementNames, ElementFinalNames, "UserControl")
        If lin.Trim <> "" Then
            FinalLinePack = New List(Of String)
            FinalLinePack.Add("")
            FinalLinesList.Add(FinalLinePack)
        End If
        FinalLinePack = New List(Of String)
        FinalLinePack.Add("End Class")
        FinalLinesList.Add(FinalLinePack)
        SaveDestinationFile(DesignerLinesList, ModuleName & ".xaml", SourceFile, SourcePath, DestinationPath, False)
        SaveDestinationFile(FinalLinesList, ModuleName & ".xaml.vb", SourceFile, SourcePath, DestinationPath, DoNotOverwriteVbSources)

    End Sub

    Private Sub CreateUserDocument(ByVal SourceFile As String, ByVal SourcePath As String, ByVal DestinationPath As String, ByVal DoNotOverwriteVbSources As Boolean)

        Dim LinesList As List(Of List(Of String))
        Dim FinalLinesList As List(Of List(Of String))
        Dim AttributesList As List(Of String)
        Dim DesignerLinesList As List(Of List(Of String))
        Dim ElementNames As Dictionary(Of String, String)
        Dim ElementFinalNames As Dictionary(Of String, String)
        Dim FilenameToUse As String
        Dim m As Integer
        Dim i As Integer
        Dim LinePack As List(Of String)
        Dim AttributeFound As Boolean
        Dim lin As String
        Dim linUpper As String
        Dim linUpperTrim As String
        Dim FinalLinePack As List(Of String)
        Dim ModuleName As String
        Dim ResourceFile As String

        LinesList = LoadSourceFile(SourceFile)
        FinalLinesList = New List(Of List(Of String))
        AttributesList = New List(Of String)
        DesignerLinesList = New List(Of List(Of String))
        ElementNames = New Dictionary(Of String, String)
        ElementFinalNames = New Dictionary(Of String, String)
        FilenameToUse = ""
        m = LinesList.Count
        i = 0
        If m > 0 Then
            LinePack = LinesList(i)
            If LinePack.Count = 1 Then
                lin = LinePack(0)
                linUpper = lin.ToUpper
                linUpperTrim = linUpper.Trim
                If linUpperTrim.StartsWith("VERSION") Then
                    ResourceFile = SourceFile.Substring(0, SourceFile.Length - 4) & ".dox"
                    i = BuildDesignerLinesList(i + 1, DesignerLinesList, LinesList, ElementNames, ElementFinalNames, ResourceFile, SourcePath, DestinationPath, "UserControl")
                End If
            End If
            Do
                AttributeFound = False
                LinePack = LinesList(i)
                If LinePack.Count = 1 Then
                    lin = LinePack(0)
                    linUpper = lin.ToUpper
                    linUpperTrim = linUpper.Trim
                    If linUpperTrim.StartsWith("ATTRIBUTE ") Then
                        If linUpperTrim.Contains("VB_NAME") Then
                            FilenameToUse = lin.Substring(linUpper.IndexOf("=") + 1).Trim.Replace("""", "")
                        Else
                            AttributesList.Add("' " & lin.Substring(linUpper.IndexOf("ATTRIBUTE ") + 10))
                        End If
                        AttributeFound = True
                    End If
                End If
                i = i + 1
            Loop While AttributeFound AndAlso i < LinesList.Count
            For Each lin In AttributesList
                LinePack = New List(Of String)
                LinePack.Add(lin)
                FinalLinesList.Add(LinePack)
            Next
        End If
        If FilenameToUse = "" Then
            ModuleName = IO.Path.GetFileNameWithoutExtension(SourceFile)
        Else
            ModuleName = FilenameToUse
        End If
        FinalLinePack = New List(Of String)
        FinalLinePack.Add("Public Class " & ModuleName)
        FinalLinesList.Add(FinalLinePack)
        FinalLinePack = New List(Of String)
        FinalLinePack.Add("")
        FinalLinesList.Add(FinalLinePack)
        lin = CleanupAndAddLines(LinesList, i, FinalLinesList, ElementNames, ElementFinalNames, "UserDocument")
        If lin.Trim <> "" Then
            FinalLinePack = New List(Of String)
            FinalLinePack.Add("")
            FinalLinesList.Add(FinalLinePack)
        End If
        FinalLinePack = New List(Of String)
        FinalLinePack.Add("End Class")
        FinalLinesList.Add(FinalLinePack)
        SaveDestinationFile(DesignerLinesList, ModuleName & ".xaml", SourceFile, SourcePath, DestinationPath, False)
        SaveDestinationFile(FinalLinesList, ModuleName & ".xaml.vb", SourceFile, SourcePath, DestinationPath, DoNotOverwriteVbSources)

    End Sub

    Private Sub CreateModule(ByVal SourceFile As String, ByVal SourcePath As String, ByVal DestinationPath As String, ByVal DoNotOverwriteVbSources As Boolean)

        Dim LinesList As List(Of List(Of String))
        Dim FinalLinesList As List(Of List(Of String))
        Dim AttributesList As List(Of String)
        Dim ElementNames As Dictionary(Of String, String)
        Dim ElementFinalNames As Dictionary(Of String, String)
        Dim FilenameToUse As String
        Dim m As Integer
        Dim i As Integer
        Dim LinePack As List(Of String)
        Dim AttributeFound As Boolean
        Dim lin As String
        Dim linUpper As String
        Dim linUpperTrim As String
        Dim FinalLinePack As List(Of String)
        Dim ModuleName As String

        LinesList = LoadSourceFile(SourceFile)
        FinalLinesList = New List(Of List(Of String))
        AttributesList = New List(Of String)
        ElementNames = New Dictionary(Of String, String)
        ElementFinalNames = New Dictionary(Of String, String)
        FilenameToUse = ""
        m = LinesList.Count
        i = 0
        If m > 0 Then
            Do
                AttributeFound = False
                LinePack = LinesList(i)
                If LinePack.Count = 1 Then
                    lin = LinePack(0)
                    linUpper = lin.ToUpper
                    linUpperTrim = linUpper.Trim
                    If linUpperTrim.StartsWith("ATTRIBUTE ") Then
                        If linUpperTrim.Contains("VB_NAME") Then
                            FilenameToUse = lin.Substring(linUpper.IndexOf("=") + 1).Trim.Replace("""", "")
                        Else
                            AttributesList.Add("' " & lin.Substring(linUpper.IndexOf("ATTRIBUTE ") + 10))
                        End If
                        AttributeFound = True
                    End If
                End If
                i = i + 1
            Loop While AttributeFound AndAlso i < LinesList.Count
            For Each lin In AttributesList
                LinePack = New List(Of String)
                LinePack.Add(lin)
                FinalLinesList.Add(LinePack)
            Next
        End If
        If FilenameToUse = "" Then
            ModuleName = IO.Path.GetFileNameWithoutExtension(SourceFile)
        Else
            ModuleName = FilenameToUse
        End If
        FinalLinePack = New List(Of String)
        FinalLinePack.Add("Public Module " & ModuleName)
        FinalLinesList.Add(FinalLinePack)
        FinalLinePack = New List(Of String)
        FinalLinePack.Add("")
        FinalLinesList.Add(FinalLinePack)
        lin = CleanupAndAddLines(LinesList, i, FinalLinesList, ElementNames, ElementFinalNames, "Module")
        If lin.Trim <> "" Then
            FinalLinePack = New List(Of String)
            FinalLinePack.Add("")
            FinalLinesList.Add(FinalLinePack)
        End If
        FinalLinePack = New List(Of String)
        FinalLinePack.Add("End Module")
        FinalLinesList.Add(FinalLinePack)
        SaveDestinationFile(FinalLinesList, ModuleName & ".vb", SourceFile, SourcePath, DestinationPath, DoNotOverwriteVbSources)

    End Sub

    Private Sub CreateClass(ByVal SourceFile As String, ByVal SourcePath As String, ByVal DestinationPath As String, ByVal DoNotOverwriteVbSources As Boolean)

        Dim LinesList As List(Of List(Of String))
        Dim FinalLinesList As List(Of List(Of String))
        Dim AttributesList As List(Of String)
        Dim ElementNames As Dictionary(Of String, String)
        Dim ElementFinalNames As Dictionary(Of String, String)
        Dim FilenameToUse As String
        Dim m As Integer
        Dim i As Integer
        Dim LinePack As List(Of String)
        Dim AttributeFound As Boolean
        Dim lin As String
        Dim linUpper As String
        Dim linUpperTrim As String
        Dim FinalLinePack As List(Of String)
        Dim ModuleName As String

        LinesList = LoadSourceFile(SourceFile)
        FinalLinesList = New List(Of List(Of String))
        AttributesList = New List(Of String)
        ElementNames = New Dictionary(Of String, String)
        ElementFinalNames = New Dictionary(Of String, String)
        FilenameToUse = ""
        m = LinesList.Count
        i = 0
        If m > 0 Then
            LinePack = LinesList(i)
            If LinePack.Count = 1 Then
                lin = LinePack(0)
                linUpper = lin.ToUpper
                linUpperTrim = linUpper.Trim
                If linUpperTrim.StartsWith("VERSION") AndAlso linUpperTrim.EndsWith("CLASS") Then
                    i = i + 1
                    LinePack = LinesList(i)
                    lin = LinePack(0)
                    linUpper = lin.ToUpper
                    linUpperTrim = linUpper.Trim
                    If linUpperTrim = "BEGIN" Then
                        i = i + 1
                        LinePack = LinesList(i)
                        lin = LinePack(0)
                        linUpper = lin.ToUpper
                        linUpperTrim = linUpper.Trim
                    End If
                    While Not linUpperTrim = "END"
                        AttributesList.Add("' " & lin.Trim)
                        i = i + 1
                        LinePack = LinesList(i)
                        lin = LinePack(0)
                        linUpper = lin.ToUpper
                        linUpperTrim = linUpper.Trim
                    End While
                    i = i + 1
                End If
            End If
            Do
                AttributeFound = False
                LinePack = LinesList(i)
                If LinePack.Count = 1 Then
                    lin = LinePack(0)
                    linUpper = lin.ToUpper
                    linUpperTrim = linUpper.Trim
                    If linUpperTrim.StartsWith("ATTRIBUTE ") Then
                        If linUpperTrim.Contains("VB_NAME") Then
                            FilenameToUse = lin.Substring(linUpper.IndexOf("=") + 1).Trim.Replace("""", "")
                        Else
                            AttributesList.Add("' " & lin.Substring(linUpper.IndexOf("ATTRIBUTE ") + 10))
                        End If
                        AttributeFound = True
                    End If
                End If
                i = i + 1
            Loop While AttributeFound AndAlso i < LinesList.Count
            For Each lin In AttributesList
                LinePack = New List(Of String)
                LinePack.Add(lin)
                FinalLinesList.Add(LinePack)
            Next
        End If
        If FilenameToUse = "" Then
            ModuleName = IO.Path.GetFileNameWithoutExtension(SourceFile)
        Else
            ModuleName = FilenameToUse
        End If
        FinalLinePack = New List(Of String)
        FinalLinePack.Add("Public Class " & ModuleName)
        FinalLinesList.Add(FinalLinePack)
        FinalLinePack = New List(Of String)
        FinalLinePack.Add("")
        FinalLinesList.Add(FinalLinePack)
        lin = CleanupAndAddLines(LinesList, i, FinalLinesList, ElementNames, ElementFinalNames, "Class")
        If lin.Trim <> "" Then
            FinalLinePack = New List(Of String)
            FinalLinePack.Add("")
            FinalLinesList.Add(FinalLinePack)
        End If
        FinalLinePack = New List(Of String)
        FinalLinePack.Add("End Class")
        FinalLinesList.Add(FinalLinePack)
        SaveDestinationFile(FinalLinesList, ModuleName & ".vb", SourceFile, SourcePath, DestinationPath, DoNotOverwriteVbSources)

    End Sub

    Private Sub Migrate(ByVal sender As Object, ByVal e As ComponentModel.DoWorkEventArgs)

        Dim srcFinalList As List(Of String)
        Dim srcList As String()
        Dim src As String
        Dim srcUpper As String
        Dim i As Integer

        Try
            srcFinalList = New List(Of String)
            srcList = IO.Directory.GetFiles(DirectCast(e.Argument, Array)(0), "*.frm", IO.SearchOption.AllDirectories)
            srcFinalList.AddRange(srcList)
            srcList = IO.Directory.GetFiles(DirectCast(e.Argument, Array)(0), "*.ctl", IO.SearchOption.AllDirectories)
            srcFinalList.AddRange(srcList)
            srcList = IO.Directory.GetFiles(DirectCast(e.Argument, Array)(0), "*.dob", IO.SearchOption.AllDirectories)
            srcFinalList.AddRange(srcList)
            srcList = IO.Directory.GetFiles(DirectCast(e.Argument, Array)(0), "*.bas", IO.SearchOption.AllDirectories)
            srcFinalList.AddRange(srcList)
            srcList = IO.Directory.GetFiles(DirectCast(e.Argument, Array)(0), "*.cls", IO.SearchOption.AllDirectories)
            srcFinalList.AddRange(srcList)
            wrk.ReportProgress(0, srcFinalList.Count)
            i = 0
            For Each src In srcFinalList
                src = IO.Path.GetFullPath(src)
                srcUpper = src.ToUpper
                If srcUpper.EndsWith(".FRM") Then
                    CreateForm(src, DirectCast(e.Argument, Array)(0), DirectCast(e.Argument, Array)(1), Convert.ToBoolean(DirectCast(e.Argument, Array)(2)))
                ElseIf srcUpper.EndsWith(".CTL") Then
                    CreateUserControl(src, DirectCast(e.Argument, Array)(0), DirectCast(e.Argument, Array)(1), Convert.ToBoolean(DirectCast(e.Argument, Array)(2)))
                ElseIf srcUpper.EndsWith(".DOB") Then
                    CreateUserDocument(src, DirectCast(e.Argument, Array)(0), DirectCast(e.Argument, Array)(1), Convert.ToBoolean(DirectCast(e.Argument, Array)(2)))
                ElseIf srcUpper.EndsWith(".BAS") Then
                    CreateModule(src, DirectCast(e.Argument, Array)(0), DirectCast(e.Argument, Array)(1), Convert.ToBoolean(DirectCast(e.Argument, Array)(2)))
                ElseIf srcUpper.EndsWith(".CLS") Then
                    CreateClass(src, DirectCast(e.Argument, Array)(0), DirectCast(e.Argument, Array)(1), Convert.ToBoolean(DirectCast(e.Argument, Array)(2)))
                End If
                i = i + 1
                wrk.ReportProgress(i)
            Next
            wrk.ReportProgress(-1, "Migration succesful.")
        Catch eMigrationFailed As Exception
            wrk.ReportProgress(-1, eMigrationFailed.ToString)
        End Try

    End Sub

    Private Sub MigrationStatus(ByVal sender As Object, ByVal e As ComponentModel.ProgressChangedEventArgs)

        If e.ProgressPercentage = 0 Then
            SourceTextBox.IsEnabled = False
            SourceButton.IsEnabled = False
            DestinationTextBox.IsEnabled = False
            DestinationButton.IsEnabled = False
            MigrateButton.IsEnabled = False
            StatusProgressBar.Visibility = Windows.Visibility.Visible
            StatusProgressBar.Maximum = e.UserState
            Cursor = Cursors.Wait
        ElseIf e.ProgressPercentage > 0 Then
            StatusProgressBar.Value = e.ProgressPercentage
        Else
            MessageBox.Show(e.UserState)
        End If

    End Sub

    Private Sub MigrationEnded(ByVal sender As Object, ByVal e As ComponentModel.RunWorkerCompletedEventArgs)

        Cursor = Nothing
        StatusProgressBar.Visibility = Windows.Visibility.Collapsed
        MigrateButton.IsEnabled = True
        DestinationButton.IsEnabled = True
        DestinationTextBox.IsEnabled = True
        SourceButton.IsEnabled = True
        SourceTextBox.IsEnabled = True

    End Sub

    Private Sub SourceButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles SourceButton.Click

        Dim dlg = New System.Windows.Forms.FolderBrowserDialog()
        Dim result As System.Windows.Forms.DialogResult = dlg.ShowDialog(Me.GetIWin32Window())

        If result = Forms.DialogResult.OK Then
            SourceTextBox.Text = dlg.SelectedPath
        End If

    End Sub

    Private Sub DestinationButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles DestinationButton.Click

        Dim dlg = New System.Windows.Forms.FolderBrowserDialog()
        Dim result As System.Windows.Forms.DialogResult = dlg.ShowDialog(Me.GetIWin32Window())

        If result = Forms.DialogResult.OK Then
            DestinationTextBox.Text = dlg.SelectedPath
        End If

    End Sub

    Private Sub MigrateButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MigrateButton.Click

        Dim DoMigration As Boolean

        DoMigration = True
        Try
            If Not IO.Directory.Exists(SourceTextBox.Text) Then
                DoMigration = False
            End If
        Catch eSourceFailed As Exception
            DoMigration = False
        End Try
        If Not DoMigration Then
            MessageBox.Show("Source directory was not found, or it couldn't be identified.")
            Exit Sub
        End If
        Try
            If Not IO.Directory.Exists(DestinationTextBox.Text) Then
                DoMigration = False
            End If
        Catch eDestinationFailed As Exception
            DoMigration = False
        End Try
        If Not DoMigration Then
            MessageBox.Show("Destination directory was not found, or it couldn't be identified.")
            Exit Sub
        End If
        If DoMigration Then
            wrk = New ComponentModel.BackgroundWorker
            wrk.WorkerReportsProgress = True
            AddHandler wrk.DoWork, AddressOf Migrate
            AddHandler wrk.ProgressChanged, AddressOf MigrationStatus
            AddHandler wrk.RunWorkerCompleted, AddressOf MigrationEnded
            wrk.RunWorkerAsync(New String() {SourceTextBox.Text, DestinationTextBox.Text, DoNotOverwriteVbSources.IsChecked.ToString})
        End If

    End Sub

End Class
